# 04. Linear table (iii) chain storage structure. Single-chain table 2. Chain-chain

Source: Internet
Author: User
Tags random seed

04. Linear table (iii) chain storage structure. Single-chain table 2. Chain-chain
Chain storage structure. Single-chain table 2

1. algorithm ideas
(1) declare a node p and q; (2) Assign the first node of the single-chain table to p (3) loop:. assign the next node to q B. release p c. assign q to p 2. Source Code Implementation:/* Initialization condition: the Single Chain linear table L already exists. Operation Result: reset the single chain table L to an empty table */typedef struct Node * LinkList; // defines the LinkList
Typedef int Status;
Status ClearList (LinkList * L) {LinkList p, q; p = (* L)-> next; // assign the first node of the single-chain table to the node p while (p) {q = p-> next; // set the next node of p to q free (p); // release node p = q; // p points to the next node q} (* L)-> next = NULL; // Finally, the single-link header node pointer field is blank returm OK ;} Iii. Advantages and Disadvantages of single-chain table structure and sequential Storage Structure 1. Storage Allocation Method(1) sequential storage structure stores data elements of a linear table in sequence using a storage unit of a link (2) A single-chain table uses a chain Storage Structure and uses any group of storage units to store elements of a linear table 2. Time Performance(1) Search: sequential storage structure O (1); single-chain table O (n) (2) Delete and insert: The sequential storage structure requires moving an average of half of the table length, the time is O (n). After a single-chain table points out a pointer at a certain position, the insertion and deletion time is only O (1) 3. Space Performance(1) The ordered storage structure requires pre-allocation of storage space, which is too large, wasted, and easily overflows. (2) The Single-linked table does not need to be allocated storage space, the number of elements is not limited.

Related Keywords:
Related Article

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.