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;