简体   繁体   English

双头链表和循环链表有什么区别?

[英]What is the difference between a Double ended linked list and a Circular linked list?

I was asked to solve a problem using a double ended linked list and a circular linked list. 我被要求使用双端链表和循环链表解决问题。

I know the double ended linked list has two pointers at the head node, one pointing to its next node and the other pointing to the last node. 我知道双头链表在头节点有两个指针,一个指向下一个节点,另一个指向最后一个节点。 This idea seems to be very similar to that of the circular linked list. 这个想法似乎与循环链表的想法非常相似。 Are the two any different from each other? 两者有什么不同吗?

In the circular linked list, the last node of the linkedlist will point back to the first node of the linked list. 在循环链表中,链表的最后一个节点将指向链表的第一个节点。 But in case of double ended linked list we will have two pointer which will point to starting node and the end node, which will help in insertion at both starting as well as end. 但是在双头链表的情况下,我们将有两个指针,分别指向起始节点和终止节点,这将有助于在起始和终止处插入。 You can check these for references. 您可以检查这些以供参考。
References 参考文献
circular linked list 循环链表
difference between double-ended linked lists and doubly-linked list 双链表和双链表之间的区别

In a circular linked list, the first node (head) points to the last node and the last node points to the first node. 在循环链表中,第一个节点(头)指向最后一个节点,最后一个节点指向第一个节点。

在此处输入图片说明

While in a double-ended linked list, each node has just one pointer which points to its next node. 在双端链表中时,每个节点只有一个指针指向其下一个节点。 it contains two pointers of this kind ("first" and "last"), so you are able to insert elements to the list from both ends of it. 它包含两个此类指针(“第一个”和“最后一个”),因此您可以从列表的两端将元素插入列表。 Also, you are able to track the last node faster through its pointer 此外,您可以通过其指针更快地跟踪最后一个节点

在此处输入图片说明

Highlight: Double-Ended - first points to last node Circular - first and last node point to themselves 突出显示:双端-第一个指向最后一个节点圆形-第一个和最后一个节点指向自己

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM