Saturday, September 12, 2015

queue class for pushing and pop from last

<?php

class Queue {
    public $number = array();
    public $index = -1;
    public function is_empty(){
        if($this->index == -1){
            return true;
        }
        return false;
    }
    public function push($element)
    {
        $this->index++;
        $this->number[$this->index] = $element;
    }
    public function pop_from_last(){
       return array_shift($this->number);
    }

}

$person = new Queue();
$person->push(2);
$person->push(4);
$person->push(8);
$person->push(9);
print_r($person->number);
echo '<br>';
echo $person->pop_from_last();
echo '<br>';
print_r($person->number);

1 comment:

  1. Best Casino Apps in Illinois (2021) - MapYRO
    Best Casino 정읍 출장안마 Apps in Illinois (2021) In Illinois, one of the best 광양 출장안마 casinos 군산 출장안마 you'll find in Illinois 김포 출장마사지 is Mohegan Sun 서산 출장샵 Pocono.

    ReplyDelete

css snippet for blogger code highlighting

code, .code {     display: block;     background: beige;     padding: 10px;     margin: 8px 15px; }