Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Queue {
- public $first, $last;
- public function __construct() {
- $this->last = null;
- $this->first = null;
- }
- public function getList() {
- $curr = $this->last;
- while ($curr != null) {
- yield $curr->data;
- $curr = $curr->next;
- }
- }
- public function contains($node) {
- foreach ($this->getList() as $curr)
- if ($curr == $node)
- return true;
- return false;
- }
- public function put($value) {
- $node = new Node($value);
- if ($this->first == null) {
- $this->first = $node;
- $this->last = $node;
- } else {
- $this->last->next = $node;
- $this->last = $node;
- }
- }
- public function get() {
- if ($this->first == null) return 'Очередь пуста';
- $item = $this->first->data;
- $this->first = $this->first->next;
- return $item;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement