Basic operations and usage of linear tables in C Language
1. Basic operations on Linear tables
InitList (* L): Initialize an empty linear table L. ListEmpty (L): determines whether the linear table is empty. If the linear table is empty, true is returned; otherwise, false is returned. ClearList (* L): clears a linear table. GetElem (L, I, * e): returns the value of the I position element in the linear table L to e. LocateElem (L, e): searches for the element equal to the given value e in the linear table L. If the query is successful, return the element serial number in the table to indicate success; otherwise, return 0 to indicate failure. ListInsert (* L, I, e): Insert the new element e at the position I in the linear table L. ListDelete (* L, I, * e): Delete the I-th position element in the linear table L and return its value with e. ListLength (L): returns the number of elements in the linear table L.
2. Why does the sequential storage structure cause storage space fragmentation"
Disadvantages of the sequential Storage Structure: The insertion and deletion of a large number of objects need to be moved; the fragmentation of storage devices; when the linear table is too large, it is difficult to determine the length.
3 What are the advantages of static linked lists? Where is it applicable?
The initial length of a static linked list is usually fixed. when inserting or deleting an object, you do not need to move the element. Instead, you only need to modify the pointer. Therefore, it still has the main advantages of the chain storage structure; in languages without pointers, static linked lists are a method for implementing linked lists using arrays.
4. What are the advantages of cyclic and bidirectional linked lists?
The two-way linked list stores pointers to the content of the linked list and can modify adjacent nodes. Sometimes the first node may be deleted, or a new node may be added before, modify the pointer to the first node.
One way to eliminate this special situation is to store a virtual node that will never be deleted or moved after the last node and form a circular linked list. The node after the virtual node is the real first node. In this case, the virtual node can be used to directly represent the linked list.
5. What types of chained storage structures are there?
There are four linear storage structures: Order, connection, index, and hash. The nonlinear storage structure includes a tree-like storage structure and a graphic storage structure.
6. What is the difference between the data length and the linear table length in the sequential storage structure?
The array length is the length of the storage space that stores the linear table. After the storage is allocated, this amount is generally unchanged;
The length of a linear table is the number of data elements in a linear table. As a linear table is inserted and deleted, this amount changes.
7. Can the operation sequence be reversed when two-way linked list is used to delete elements?
You only need to save the pointer member in a temporary variable before the change. It doesn't matter which one you want to change first.
8. The sequential storage structure now has those applications
If a linear table needs to be searched frequently and seldom inserted or deleted, the sequential storage structure should be used.
9. Single-chain table
The information stored in the pointer domain is a pointer or chain. These two pieces of information constitute a data element called a storage image or a Node ). N nodes are linked into a linked list, which is a linear table (a1, a2, a3 ,..., An. Because each node of the linked list contains only one pointer field, it is called a single-chain table.
10 what is a pointer Field
In the chain storage structure, in addition to storing the information of data elements, it also stores the storage address (pointer) of its successor elements ). That is to say, in addition to storing its own information, it also needs to store information indicating its direct successor storage location. The domain that stores the data element information is called the data domain, and the domain that stores the direct successor location is called the pointer domain.