(1) which tables are implemented?-4.
Linear tables can be implemented in two ways: Sequential Representation and linked list implementation.
A linear table represents the uniqueness and continuity between data elements (such as the English alphabet ).
Sequential RepresentationIt refers to storing the data elements of a linear table in sequence with a set of sequential storage units..
LOC (A + 1) = LOC (A) + 1; // LOC (A) is the storage location of the first data element in A linear table, the starting position or base address of the linear table.
An ordered table (Sequential Representation) is characterized by the fact that elements are physically adjacent to each other in a computer to represent the logical relationship between data elements in a linear table.
You need to allocate the table size in advance. After the original size is exceeded, you need to re-allocate the continuous space.
Chained RepresentationIt refers to the data element of a linear table with any storage unit. Relationship between elements. In the linked list description, each element of the data object instance is described in a unit or node. Each node contains the location information of other nodes related to the node. Such location information about other nodes is called a chain or a pointer.
Template <class T>
Class Node
{
Private:
T data; // node Value
Node <T> * link; // pointer to the next Node pointed by the Node
}
No pre-allocation is required. Additional information needs to be stored to implement the logical relationship of the table.
Basic operations of a linear table include initializing a table, clearing a table, determining whether the table is empty, obtaining the table length, obtaining the elements in the table, obtaining the previous element of the table, and inserting the element, delete.
-- Compiled from the C/C ++ programmer interview book