ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Queue.php
Go to the documentation of this file.
1<?php
2
21 private $input;
22 private $output;
23
24 public function __construct($input = array()) {
25 $this->input = $input;
26 $this->output = array();
27 }
28
32 public function shift() {
33 if (empty($this->output)) {
34 $this->output = array_reverse($this->input);
35 $this->input = array();
36 }
37 if (empty($this->output)) {
38 return NULL;
39 }
40 return array_pop($this->output);
41 }
42
46 public function push($x) {
47 array_push($this->input, $x);
48 }
49
53 public function isEmpty() {
54 return empty($this->input) && empty($this->output);
55 }
56}
A simple array-backed queue, based off of the classic Okasaki persistent amortized queue.
Definition: Queue.php:20
__construct($input=array())
Definition: Queue.php:24
isEmpty()
Checks if it's empty.
Definition: Queue.php:53
push($x)
Pushes an element onto the front of the queue.
Definition: Queue.php:46
shift()
Shifts an element off the front of the queue.
Definition: Queue.php:32
$x
Definition: example_009.php:98