Implementing a two-way queue

Source: Internet
Author: User
Class Deque{public $queue = Array ();p ublic $length = 0;public function Rpop () {$node = Array_pop ($this->queue); $this-&G T;countque (); return $node;} Public Function Rpush ($node) {Array_push ($this->queue, $node); $this->countque (); return $this->queue;} Public Function Lpop () {$node = Array_shift ($this->queue); $this->countque (); return $node;} Public Function Lpush ($node) {array_unshift ($this->queue, $node); $this->countque (); return $this->queue;} Private Function Countque () {$this->length = count ($this->queue);}}

Redis implements its own double-ended linked list structure.
• The double-ended linked list has two main functions: ◦ as one of the underlying implementations of the Redis list type;
◦ as a general data structure, used by other functional modules;

• The performance characteristics of the double-ended linked list and its nodes are as follows: ◦ The nodes have precursors and successors, the complexity of accessing the precursor and successor is O (1), and the iteration of the linked list can be made from the table header to the footer and from the footer to the table head in two directions;
◦ The list has pointers to the header and footer, so the complexity of processing the header and footer is O (1);
◦ The list has attributes of the number of nodes, so the number of nodes (length) of the linked list can be returned within the O (1) complexity;

  • 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.