05. Linear table (4) chain storage structure. Static linked list

Source: Internet
Author: User
Chain storage structure. static linked list 1. Static linked list 1. the single-chain table of the static linked list storage structure is implemented through pointers, but we can also use arrays to describe the single-chain table instead of pointers, that is, the static linked list. How to Implement static linked list? The element of the constructed array is composed of two data fields: data and cur. That is, each lower mark of the array corresponds to one data and one cur. Data

Chain storage structure. static linked list 1. Static linked list 1. the single-chain table of the static linked list storage structure is implemented through pointers, but we can also use arrays to describe the single-chain table instead of pointers, that is, the static linked list. How to Implement static linked list? The element of the constructed array is composed of two data fields: data and cur. That is, each lower mark of the array corresponds to one data and one cur. Data

Chain Storage Structure-static linked list I. Static linked list 1. Static linked list Storage StructureA single-chain table is implemented through pointers, but we can also use arrays to describe a single-chain table, that is, a static linked list. How to Implement static linked list? The element of the constructed array is composed of two data fields: data and cur. That is, each lower mark of the array corresponds to one data and one cur. Data Field data: used to store data elements, that is, the data to be processed. cursor cur: used to store the subscript of the element in the array, which is equivalent to the next pointer in a single-chain table. To facilitate data insertion, we usually create a larger array so that there is some free space without Overflow. Static linked list storage structure of a linear table: # define MAXSIZE 1000 // assume that the length of the linked list is 1000 (elements) typedef struct {ElemType data; // data field, int type int cur; // Cursor (Cursor). If it is 0, it indicates no point} Component, StaticLinkList (MAXSIZE ); 2. Backup linked listSince the first and last elements of the array are processed as special elements and no data is stored, we call unused array elements a backup linked list. Therefore, we stipulate that: (1) the cursor cur of the first element of the array (that is, the element with the subscript 0) stores)] subscript of an idle space element (the first element of the standby linked list); (2) the cursor of the last element of the array, cur, stores the subscript of the first element with a numerical value (equivalent to the header node in a single-chain table ). When the entire linked list is empty, the cursor cur of the last element is 0. (3) The last cur with a value element in the linked list is 0.

Sublimation Note: How to chain each component in a one-dimensional array list into a backup linked list? Typedef int StatusStatus InitList (StaticLinkList list) {int I; // I is an array subscript, and MAXSIZE is the chain table length for (I = 0; I 2. Insert/delete a static linked list <喎?http: www.2cto.com kf ware vc " target="_blank" class="keylink"> Examples + s/examples + examples/examples + MS6 + ssyswbSx7bXEsuXI67LZ1/examples/fK/examples + examples/1c/Qt9bBv8/examples/K/cvjt6ijugphLrvxyKHK/examples/Examples/ release/release/CseootbHHsMr91 + release/Vz9C1xM/release + release/KMr91 + release + dLUsNG31sG/release + release/Vz9C31sG/release/ xotLio7prytfPyMrH1 + 6689K7uPbUqsvYtcTPwrHqICAgIAogICAgaWYoaiZsdDsxIA = "| j> ListLength (L) + 1) return ERROR; j = Malloc_SLL (L); //. returns the subscript of the idle component if (j) {L [j]. data = e; // B. assign data to the data for (m = 1; m) of this component 2. Delete static linked listSource code implementation/* 1. reclaim the idle node with the subscript k to the backup linked list */void Free_SSL (StaticLinkList space, int k) {space [k]. cur = space [0]. cur; // assign the first element cur (its value is the first idle element subscript of the backup linked list) to the cur space [0] to delete the component. cur = k; // assign the subscript of the component to be deleted to the cur}/* 2 of the first element. delete the I-th Data Element e */typedef int StatusStatus ListDelete (StaticLinkList L, int I) {int I, k; if (I <1 "| I> ListLength (L) return ERROR; k = MAXSIZE-1; // store the subscript for (j = 1; j <= I-1; j ++) k = L [k]. cur; // locate the previous element of the element to be deleted, and assign its cur value K (subscript of the element to be deleted) j = L [k]. cur; // assign the cursor value of the deleted element to j, that is, the value is the subscript of the next element L [k]. cur = L [j]. cur; Free_SSL (L, j);}/* 3. initial Condition: the static linked list L already exists. Returns the number of data elements in L */int ListLength (StaticLinkList L) {int j = 0; int I = L [MAXSIZE-1]. cur; while (I) {I = L [I]. cur; j ++;} return j ;}
Iii. Advantages and Disadvantages of static linked lists 1. AdvantagesDuring the insert and delete operations, you only need to modify the cursor and do not need to move elements. This improves the disadvantages of the insert and delete operations in the sequential storage structure that need to move a large number of elements; 2. Disadvantages(1) the problem that the table length is hard to be determined due to the continuous storage allocation is not solved; (2) the random access feature of the sequential storage structure is lost;

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.