Showing posts with label queue. Show all posts
Showing posts with label queue. Show all posts

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);

css snippet for blogger code highlighting

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