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.

Data Link List structure (Circular Linked List) Picture 1

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.

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

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)

4 ★ | 1 Vote

May be interested

  • Structure (Struct) in C #Structure (Struct) in C #
    in c #, a structure is a data type. it helps you create a single variable that keeps relevant data of diverse data types. the keyword struct in c # is used to create a structure.
  • Data structure in C / C ++Data structure in C / C ++
    struct in c / c ++ arrays in c / c ++ allow you to define several types of variables that can hold the values ​​of several members of the same data type. but the structure is another type of data in the c / c ++ programming language, which allows you to combine other types of data.
  • Heap data structureHeap data structure
    data structure the heap is a special case of a balanced binary tree data structure, where the root node's key is compared to its children and arranged accordingly.
  • Hash Table data structureHash Table data structure
    the hash table data structure is a data structure that stores data in a federated manner. in hash table, data is stored in array format, in which data values ​​have their own index values. accessing data becomes faster if we know the index of the data to find.
  • Add Structure to Diagram in Visio 2010 using List and ContainerAdd Structure to Diagram in Visio 2010 using List and Container
    in the microsoft visio 2010 model design application, one of the most used features is to assign a structure - structure to the chart - diagrams using containers, lists and callouts. in the following article, we will go deeper and learn more about the above concepts and how to use them accordingly ...
  • Structure (Struct) in C programmingStructure (Struct) in C programming
    arrays in c allow you to define several types of variables that can hold the values ​​of several components of the same type. but the structure is another type of data in the c programming language, which allows you to combine other types of data.
  • How to link data between spreadsheets in Google SheetsHow to link data between spreadsheets in Google Sheets
    most of us are familiar with basic operations when using spreadsheets in google sheets such as using specific rows and columns, calculating, creating pie charts, columns, data lines, etc. however, today's article will show you how to link data between spreadsheet pages in google sheets.
  • Graph data structure (Graph)Graph data structure (Graph)
    a graph (graph) is a form of visual representation of a set of objects in which pairs of objects are connected by links. interconnected objects are represented by points called vertices, and links that connect vertices are called edges.
  • How to create Hyperlink to link spreadsheets in ExcelHow to create Hyperlink to link spreadsheets in Excel
    when creating hyperlink on excel, we can link data tables together or access a new spreadsheet file quickly.
  • Is the data structure and algorithm necessary for a Web Developer?Is the data structure and algorithm necessary for a Web Developer?
    is the data structure and algorithm necessary for a web developer? let's tipsmake.com find out in the article below!