Data Structure 2.5 Other Forms of linear table, data structure 2.5

Source: Internet
Author: User

Data Structure 2.5 Other Forms of linear table, data structure 2.5
1 // single-cycle linked list (connect two single-cycle linked lists L1 and L2. After the first data element node of L2 is connected to the last node of L1, the time complexity O (n) optimized to O (1) 2 q = r1-> next; // save L1 header node pointer 3 r1-> next = r2-> next; // connect L1 and L2 tail headers to 4 free (r2 _> next); // release L2 table header node 5 r2-> next = q; // create a circular linked list 6 7 // bidirectional linked list 8 // define a bidirectional linked list node 9 typedef struct dunode10 {11 datatype data; 12 struct dunode * prior, * next; 13} DulNode, * DulLinkList; 14 // insert operation (set q to point to a node in the two-way linked list, s to the new node with the value of e to be inserted, and insert * s to the front of * q) 15 s-> prior = q-> prior; // (1) 16 q-> prior = s; // (2) (1) (2) the order cannot be changed, otherwise, * q's direct precursor node pointer will lose 17 q-> prior-> next = s; 18 s-> nsxt = q; 19 // delete operation (set q to point to a node in the two-way linked list and delete * q) 20 q-> next-> prior = q-> prior; // (1) 21 q-> prior-> next = q-> next; // (2) (1) (2) the order can be changed by 22 free (q ); 23 24 // static linked list 25 // define the array S26 # define MAXSIZE 100027 typedef struct28 {29 datatype data; 30 int next; 31} SNode; // node type 32 SNode S [MAXSIZE]; 33 int SL, SX; // two header pointer variables. The SL header pointer represents the user's linear table, SX head pointer pointing to a linked list composed of idle nodes 34 // apply for a Node space (apply to the SX idle linked list and cannot call the system function malloc () 35 if (SX! =-1) // 36 {37 t = SX when SX is not empty; // The allocated Node Address (subscript) is stored in t 38 SX = S [SX]. next; // after the next node is given to the user, the SX pointer is moved to the next node location 39} 40 // reclaim the Node space (recycle to SX through the phase address t of the node, the system function free () cannot be called for 41 s [t]. next = SX; 42 SX = t;View Code

Note:
1. Single-cycle linked list
The pointer field of the last node of the single-chain table is no longer a null pointer but is changed to a head node. The linked list header and the end node are connected to form a single-cycle linked list;
If operations on a single-linked table are usually performed at the end of the table and the header, you can change the identification method of the linked list, that is, using a method pointing to the end node without the head pointer h.
The pointer r is used to identify the circular linked list, improving the operation efficiency.
2. Two-way linked list
Each node adds a pointer field pointing to the direct precursor. The linked list composed of such nodes is called a two-way linked list.
3. Static linked list
A one-dimensional array is used to describe a Linear Linked List. An array belongs to a static storage structure. The linked list described in this method is called a static linked list.
The pointer field records the relative address of the next logically adjacent Data Element (the subscript of the array in this structure), which is called a static pointer.
If the defined array does not have a unit whose subscript is-1, the NULL pointer is represented by-1.

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.