Data Link List structure (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.

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.

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.

Picture 1 of Data Link List structure (Circular Linked 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.

Picture 2 of Data Link List structure (Circular Linked List)

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.

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.

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.

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.

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've just finished reading the article "Data Link List structure (Circular Linked List)" edited by the TipsMake team. You can save data-link-list-structure-circular-linked-list.pdf to your computer here to read later or print it out. We hope this article has provided you with many useful tech tips and tricks. You can search for similar articles on tips and guides. Thank you for reading and for following us regularly.

« PREV Stack data structure (Stack)
NEXT » Data structure of double linked list