Data Structures Algorithms 简明教程
Circular Linked List Data Structure
What is Circular Linked List?
Circular Linked List 是链表的一个变体,其中第一个元素指向最后一个元素,而最后一个元素指向第一个元素。单向链表和双向链表都可以变成循环链表。
Basic Operations in Circular Linked List
循环列表支持以下重要操作。
-
insert − 在列表开头插入一个元素。
-
delete − 从列表开头删除一个元素。
-
display − 显示列表。
Circular Linked List - Insertion Operation
循环链表的插入操作只在列表开头插入元素。这不同于通常的单链表和双向链表,因为此列表中没有特定的开始和结束点。插入在列表的开头或特定节点(或给定位置)之后。
Circular Linked List - Deletion Operation
循环链表的删除操作可以从列表中删除特定节点。这种类型的列表中的删除操作可以在开始处或给定位置或结束处执行。
Algorithm
1. START
2. If the list is empty, then the program is returned.
3. If the list is not empty, we traverse the list using a
current pointer that is set to the head pointer and create
another pointer previous that points to the last node.
4. Suppose the list has only one node, the node is deleted
by setting the head pointer to NULL.
5. If the list has more than one node and the first node is to
be deleted, the head is set to the next node and the previous
is linked to the new head.
6. If the node to be deleted is the last node, link the preceding
node of the last node to head node.
7. If the node is neither first nor last, remove the node by
linking its preceding node to its succeeding node.
8. END