Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of python double-ended linked list

Shulou Source: shulou.com Published: 2022-06-03 15:33:50 09月29日 Update

This article mainly shows you the "python double-ended linked list example analysis", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "python double-ended linked list example analysis" this article.

1. A node of a double-ended linked list has two pointers, pointing to the previous node and the latter node, respectively.

2. Double-ended linked list is a data structure composed of prev (front-drive pointer) and next (rear-drive pointer).

These two are used to build the relationship between nodes.

Example

Class DoubleNode: def _ _ init__ (self,item): self.item = item self.next = None self.prior = None class HandleDouNode: def create_node_head (self Li): head = DoubleNode (li [0]) for element in li [1:]: node = DoubleNode (element) node.next = head # the pointer of the new node is linked to the original head node head.prior = node # the previous pointer of the original head node is linked to node head = node # the header node points to node return head def create_node_tail (self Li): head = DoubleNode (li [0]) tail = head for element in li [1:]: node = DoubleNode (element) tail.next = node # the next pointer of the original tail node is linked to the node node.prior = tail # node node the previous pointer is connected to the original tail tail = node # modify the tail finger The needle is node return head def print_node (self Head): while head: print (head.item,end=',') head = head.next hdn = HandleDouNode () head = hdn.create_node_tail print (head.item) print (head.next.item) print (head.next.prior.item) "" OUT121 "above are all the contents of the article" sample Analysis of python double-ended linked lists " Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Pointers nodes examples analysis content tail articles nodes links two points learning help between precursors instances data data structures easy to understand more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Tech Info OPPO Reno Shulou Information Microsoft