Data structure of (1) linked list

Source: Internet
Author: User

Introduction

A linked list is a non-sequential, non-sequential storage structure on a physical storage unit, and the logical order of the data elements is achieved through the order of the pointers in the linked list.

A linked list consists of a series of nodes (each element in the list is called a node) that can be dynamically generated at run time.

Each node consists of two parts: one is the data field that stores the data element, and the other is the pointer field that stores the next node address.

The operation is complex compared to the linear table order structure. Since they do not have to be stored sequentially, the list can achieve an O (1) complexity at the time of insertion, much faster than another linear table-order table, but the time to find a node or to access a particular numbered node requires O (n), while the corresponding time complexity of the linear and sequential tables is O (Logn) and O (1) respectively.

Using the list structure can overcome the shortcoming that the array list needs to know the data size beforehand, the list structure can make full use of the computer memory space and realize the flexible memory dynamic management. However, the list loses the advantage of random array reading, and the spatial overhead of the linked list is larger due to the increase of the point-of-view pointer domain.

The most obvious benefit of a linked list is that the regular array arranges the associated items in a different way than the data items are in the order of memory or disk, and the data accesses tend to be converted in different permutations. Lists allow you to insert and remove nodes from any location on the table, but do not allow random access.

There are a number of different types of linked lists: one-way lists, two-way lists, and circular lists.

One-way linked listConcept:one-way linked list (single linked list) is a kind of linked list, which is characterized by the link direction of the linked list is one-way, access to the linked list is to be read sequentially from the head; A list of lists that are constructed using pointers, also known as node lists, because the linked list is assembled by nodes. where each node has a pointer member variable that refers to the next node in the list;

The list is made up of nodes, and the head pointer points to the first node that becomes a table header and terminates at the last pointer to null;

/**2015 February 27 16:42:27 by: I love the process **//** function: Create, insert, print single-linked list (SINGLELINKLIST--SLL) **/#include <stdio.h> #include <          malloc.h>//0. Single-linked list (SLL) node typedef struct NODE{CHAR data;  Data domain struct node *next; Pointer field}LNODE;//1. Initializes a single-linked list (SLL), returns a list-head pointer Lnode *initsll () {//Opens head node Lnode *head = null;//initialization succeeded if (NULL! = (Head = (Lnode *) Mall OC (sizeof (Lnode))) Head->next = Null;return Head;} 2. Insert node in single-linked list (SLL) "head interpolation"///head---linked header pointer///data---the data to be inserted int InsertNode1 (Lnode *head, char data) {Lnode *  PNode1 = Null;int YesNo = 0; Default node opening failure//node opening success if (NULL! = (PNode1 = (Lnode *) malloc (sizeof (Lnode)))) {pnode1->data = data;//insert node into linked list (SLL) Head Pnode1->next = Head->next;head->next = PNode1; YesNo = 1;} return YesNo;} 3. Print single-linked list (SLL)///head----linked header pointer void displaysll (Lnode *head) {Lnode *h = head->next;while (NULL! = h) {printf ("%c", H-&gt ;d ata); h = H->next;}} int main (void) {Lnode *head = null;//1. Initialize single-linked list (SLL) head = INITSLL ();//2. Insert Node "head interpolation" InsertNode1 (Head, ' a '); InsertNode1 ( Head, ' B '); InsertNode1 (heaD, ' C '); InsertNode1 (head, ' d '); InsertNode1 (head, ' e ');//3. Print single-linked list (SLL) displaysll (head); return 0;} 
Circular link List

Concept: The circular chain list is another form of chain-storage structure. Its characteristic is that the pointer field of the last node in the table points to the head node, and the entire list forms a ring.


Here, we change the initialization part of the one-way linked list slightly to form a circular single-linked list.

1. Initialize the circular link list (CL), return the linked list head pointer Lnode *initcl () {//Open head node Lnode *head = null;//initialization succeeded if (NULL! = (Head = (Lnode *) malloc (sizeof (LNo DE))) {//here with "#" Mark head node Head->data = ' # ';//link the list ~~~head->next = head;} return head;}

(not to be continued ...) )


Reference Documents:

1) Baidu Encyclopedia, linked list, http://baike.baidu.com/view/549479.htm,2015 February 27 17:22:48

2) Baidu Encyclopedia, one-way linked list, http://baike.baidu.com/view/2073053.htm,2015 February 27 17:23:05

3) Baidu Encyclopedia, circular link list, http://baike.baidu.com/view/178643.htm,2015 February 27 17:49:00


Data structure of (1) linked list

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.