[C Resolution 9] a preliminary study on linked list

Source: Internet
Author: User

A Preliminary Study on the nine linked list in C Resolution
The linked list can better adapt to the storage needs of real-time changes and has unlimited scalability. However, you do not need to worry about whether there is enough continuous memory.

1. Advantages of linked list:

  • Continuous memory constraints: the Array Memory must be continuous. When the storage data volume reaches a certain level, opening up the array space may face a serious problem-the memory cannot find enough continuous memory. The linked list does not require continuous memory. It can concatenate scattered memory to extend the length of the table.
  • Insert and delete: The insertion and deletion of arrays requires a large amount of data to be moved, and there is uncertainty in time consumption. When data changes in real time, the efficiency of arrays is very low. The deletion and insertion of a linked list only requires several pointers, which consumes a fixed amount of time and is highly efficient.
  • Better Applicability: even if it is a dynamic array, if you encounter a larger storage demand, you must re-open a larger array and copy data. The linked list can meet almost any size and changing storage requirements.
2. List structure: Linked lists are formed by nodes and linked to each other. What are the characteristics of the nodes that make up the linked list? First, the linked list is used to store data. Therefore, the nodes must have a data storage area. Furthermore, the linked list must be linked to each other. Obviously, there is a pointer storage area.
Data storage zone: stores data information. Pointer storage area: stores a pointer to point to the next node.
It is easy to understand that the pointer of a node points to the next node, and the next point points to the next... it forms a chain. Obviously, the node of the linked list needs to be defined as a struct, which contains the data part and pointer part. 3. Create a linked list:
  • Step 1: Define a node.
  • Second, no: add nodes to form a linked list.
The following is an example of creating a linked list: In the preceding sample code //***************************//********* **// Add the node to the end of the linked list and // output the linked list //***************************//********* ** The while control conditions, pointer-related operations and other details in the two sections of Code may not be very clear, and it is difficult to form an intuitive understanding. It doesn't matter. In this section, we first focus on the overall structure of the linked list to form a preliminary understanding of the linked list. In the next article, we will give you an intuitive analysis of the image.

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.