Data Link List structure (Circular Linked List)
What is a round list (Circular Linked List)?
The linked list (Circular Linked List) is a variant of the Linked List, in which the first element points to the last element and the last element points to the first element.
Both types of Single Link List (Singly Linked List) and Double Listed List (Doubly Linked List) can all be created as a Round Link List. Below we will learn how to create one.
Create a linked Link List from a single linked list
In the Single Linked List, the next point to the end of the last node points to the first node, instead of pointing to NULL.
Create List of linked links from the Double Link List
In the Double-Link List, the next point of the last node points to the first node and the point pointing to the front of the previous node points to the last node. This process will form a ring in both directions.
Looking at the two illustrations above, you need to keep in mind:
Last Link's next pointer points to First Link in both cases with the Single Link List as well as the Double Link List.
First Link's Prev points to the last element of the Linked List in case of Double Link List.
Basic activities on the Round Link List
Here are some basic activities supported by the Round Link List:
Insert operation : insert an element into the starting position of the Round Link List.
Delete operation : delete an element of the Round Link List.
Display : display the entire Round Link List.
Insert operation in the Round Link List
The following is an algorithm that illustrates the insert operation in the Round Link List based on the Single Link List.
//Chèn link tại vị trí đầu tiên void insertFirst ( int key , int data ) { //tạo một link struct node * link = ( struct node *) malloc ( sizeof ( struct node )); link -> key = key ; link -> data = data ; if ( isEmpty ()) { head = link ; head -> next = head ; } else { //trỏ nó tới first node cũ link -> next = head ; //trỏ first tới first node mới head = link ; } }
To monitor the code deployment section illustrating in detail in C language, go to the chapter: Program List of linked links in C.
Delete operation in the Round Link List
Below is an algorithm that illustrates the delete operation in the Round Link List based on a single linked list.
//Xóa phần tử đầu tiên struct node * deleteFirst () { //Lưu tham chiếu tới first link struct node * tempLink = head ; if ( head -> next == head ){ head = NULL ; return tempLink ; } //Đánh dấu next tới first link là first head = head -> next ; //trả về link đã bị xóa return tempLink ; }
To monitor the code deployment section illustrating in detail in C language, go to the chapter: Program List of linked links in C.
Show List of linked links
Here is an algorithm that illustrates the operation of displaying the entire Round Link List.
//Hiển thị danh sách liên kết vòng void printList () { struct node * ptr = head ; printf ( "n[ " ); //Bắt đầu từ vị trí đầu tiên if ( head != NULL ) { while ( ptr -> next != ptr ) { printf ( "(%d,%d) " , ptr -> key , ptr -> data ); ptr = ptr -> next ; } } printf ( " ]" ); }
To monitor the code deployment section illustrating in detail in C language, go to the chapter: Program List of linked links in C.
According to Tutorialspoint
Previous article: Linked list data structure (Linked List)
Next article: Stack data structure (Stack)
You should read it
- Data structure of double linked list
- Linked list data structure (Linked List)
- How to create a drop list in Excel 2016
- The To-do List is good, the Done List is very good, but the Do-Not-Do List is much better
- Create a list of tables in Word automatically
- How to Create a List in Cells in Excel
- How to create a list of 'dream' App Store apps on iPhone
- Work with lists in PowerPoint 2016
- 7 How to increase the size of the ring 1 for her chest
- How to list all applications on Mac
- How to create List Box in Excel
- How to create a to-do list on Facebook
Maybe you are interested
PowerPoint 2016: Working with lists in PowerPoint
List of fruits voted the rarest and most delicious in the world
Google announces list of best apps and games on Play Store in 2024
Apple announces list of best apps and games on App Store in 2024
List of top 5 strongest golden strikers in the world
List of fish species in The Depths in Fisch Roblox