Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

Data Link List Structure (Circular Linked List)

Understand Data Link List Structure (Circular Linked List) with clear explanations, practical examples, and useful tips. This updated guide covers the...

Table of Contents

Data Link List Structure (Circular Linked List) is easier to understand when the core ideas are paired with practical examples. The sections below explain the topic clearly, highlight useful steps, and point out details that can prevent common errors.

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 you 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.

Data Link List Structure (Circular Linked List) example image 1

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.

Data Link List Structure (Circular Linked List) example image 2

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 ( " ]" ); } 

FAQ

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.

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.

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.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.