Linked List queue of php Data Structure and php Data Structure queue

Source: Internet
Author: User

Linked List queue of php Data Structure and php Data Structure queue

Php linked list queue

Instance code:

class Queue{     private $last;   private $first;   private $oldfirst;   private static $n=0;      public function __construct(){     $this->last   = null;     $this->first  = null;     $this->oldfirst = null;   }      public function push($item){     $this->oldfirst = $this->last;     $this->last = new Node();     $this->last->item = $item;     $this->last->next = null;     if(empty($this->first)){       $this->first = $this->last;     }else{       $this->oldfirst->next = $this->last;     }     self::$n++;   }      public function pop(){     if(self::$n<0){       return null;     }     $item = $this->first->item;     $this->first = $this->first->next;     self::$n--;     return $item;   }    }  class Node{   public $item;   public $next; }  $Queue = new Queue(); $Queue->push("a"); $Queue->push("b"); $Queue->push("c"); echo $Queue->pop().PHP_EOL; echo $Queue->pop().PHP_EOL; echo $Queue->pop().PHP_EOL; echo $Queue->pop().PHP_EOL;

If you have any questions, please leave a message or go to the community on this site for discussion. Thank you for reading this article. Thank you for your support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.