Tutorial on implementing the array linked list function in C language, and tutorial on arrays in C Language

Source: Internet
Author: User

Tutorial on implementing the array linked list function in C language, and tutorial on arrays in C Language
Description

Main functions: to implement a data structure, you must have the following three functions:

The quick Node Deletion function of the linked list provides the quick search function of arrays. For example, you can use index to find data nodes and store any type of data.

Implementation Interface Method

The following methods are implemented based on the commonly used methods of linked lists and arrays: (Zeng, deletion, modification, and query)

Implement the super_array structure initialization method; implement the super_array structure data insertion method (insert data nodes from the beginning); Implement the super_array structure data query method (byName match and byIndex match ); implement the super_array structure deletion Node Method (byName match); Implement the super_array Structure Modification Node Method (byName match and byIndex match );

Use

Compile the Code:

make super_array_test

Compile and execute:

make all

Clear:

make clean

Run the test case separately:

cd ${src_dir}./super_array_test.out
Design

Super_array node data structure:

struct super_array_node {
     int next; // Next node index
     int previous; // Previous node index
     int valid; // Whether the current node is valid
     void * data; // Data information pointer
}

The super_array header is defined as follows:

struct super_array_header {
     int first; // super_array index of the first node
     int total_len; // Total number of node nodes
     int len; // Number of used node nodes
     int increase_len;
     p_super_array_node r_array; // super_array_node array, malloc allocation
     link_node freelist; // Save the current free node index-> nodes in this linked list are all free
} 

In the super_array_header data structure, the super_array node array stores data information, and the freelist linked list records the indexes of all current idle nodes;

Has the following features:

1.Use arrays to implement the linked list function, so that it can quickly delete linked lists and quickly search for arrays;

2. The freelist linked list stores the index information of idle nodes. When you need to use idle nodes, retrieve the index from this linked list and locate the idle node directly;

3. void * is a common data type and can freely define the stored data;

4. dynamically grow the memory space based on the current usage;

5. Provides callback functions to facilitate expansion;

Use Cases

In disk space, the size, space, and number of nodes of our storage space are fixed, and the distribution and arrangement are like an array. In addition, you can quickly locate the node location and obtain data based on the index number. However, in data abstraction, nodes are often chained like linked lists (the spatial data meanings of nodes are different) and processed separately Based on the Data Types in the nodes;


Related Article

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.