Learning data structure (6)-generalized table

1. What is a generalized table?

A generalized table is a sequence of n table elements. If n=0, it is called an empty table. Set a_{i}the same as for the i-th element of the generalized table, the generalized table represents a general linear GL table: GL=(a_{1},a_{2},\cdots ,a_{i},\cdots,a_{n}). Among them, n represents the length of the generalized table, that is, the number of elements contained in the generalized table, and n \ geq0. If it a_{i}is a single data element, it a_{i}is an atom of the generalized table GL; if it a_{i}is a generalized table, it a_{i}is a subtable of the generalized table GL. The generalized table has the following properties: (1) Order: the data elements in the generalized table have relative order. (2) With length: The length of the generalized table is defined as the number of elements contained in the outermost layer. (3) Depth (4) Shareable: A generalized table can be shared by other generalized tables. (5) Recursive: A generalized table can be its own subtable. This generalized table is called a recursive table. The depth of the recursive table is an infinite value, and the length is a finite value. (6) Multi-level: Any non-empty generalized table GL can be decomposed into a header and a footer.

Generalized table is a recursive data structure, it is difficult to allocate a fixed size of storage space for it, can only use a dynamic chain structure. The storage structure is divided into head and tail notation and child brother notation.

(1) Head and tail notation

Its storage mode includes two forms: (1) Table node, which is composed of a pointer hp to the head of the table, a pointer to tp to the end of the table, and a node flag (value 1) (2) Element node: a node The point flag (value is 0) and the element value data.

(2) Child brother notation

There are also two node modes: (1) Sub-table node: including the flag field (value 1), the pointer field hp pointing to the first child, and the pointer field tp pointing to the brother. (2) Including the flag field (the value is 0), the data data, and the pointer to the brother.

2. Generalized table operation

In this method, the divide-and-conquer method is often used for recursive operations, that is, the generalized table is divided into a header and a footer for processing.

(1) Replication of generalized tables

The copy is divided into two parts, one is to copy the head element, and the other is to copy the child table. Copy all the nodes pointed by the head pointer of the generalized table to a new generalized table.

(2) Destruction of generalized tables

The destruction of the generalized table is to release all the nodes pointed to by the head pointer. The nodes include the head element and the sub-table.

(3) Take the head element and the tail element

Taking the head element of the generalized table is to return the address of the atom or subtable pointed to by the head pointer of the node; and the tail element of the generalized table must be a subtable.

(4) Add and delete header elements

Insert an element at the head of the generalized table.

(5) Calculation depth and breadth

The length of the generalized table is the number of elements of the generalized table, that is, the number of nodes at the highest level of the generalized table; the multiplicity of the generalized table is the multiplicity of the parentheses in the generalized table.

Depth(LP)=\left\{\begin{matrix} 1 LP==NULL\\ 0 LP==atom \\ MAX(p_{1},p_{2},\cdots,p_{n})+1 LP==list \end{matrix}\right.

(6) Generalized table traversal

 

Guess you like

Origin blog.csdn.net/qq_35789421/article/details/113774530
Recommended