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
- 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
May be interested
- 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 ++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 structuredata 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 structurethe 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 Containerin 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 programmingarrays 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 Sheetsmost 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)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 Excelwhen 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? let's tipsmake.com find out in the article below!