Data structure-4.6 strings, arrays and generalized tables
Preface-Data Structure
The data structure needs to be chewed repeatedly, and the answers to the problems encountered in the development can be obtained at any time.
Generalized table
- definition
- Generalized table is also called list, which is an extension of linear table and a finite sequence of data elements. Recorded as: LS= (d0, d1, d2… dn-1). Among them, di can be either a single element or a generalized table.
- Description
- The definition of the generalized table is a recursive definition because the generalized table is used when describing the generalized table:
- In a linear table, the data element is a single element, and in a generalized table, the element can be a single element called a single element (originally), or it can be a subtable of a generalized table called a generalized table:
- n is the generalized table length:
- example
- A is an empty list, the length of the list is 0
A = ()
- The table length of B is 2, and the two elements are a and subtables (b, c, d)
B = (a,(b,c,d))
- There is only one element e in C, and the table length is 1
C = (e)
- The table length of D is 4, its first three elements A, B, and C are generalized tables, and the fourth is a single element
D = (A,B,C,f)
- E is the recursive list
E = (a,E)
- Operation of the generalized table Note that the tail of the table is a table composed of the remaining elements. You must add a bracket ()
- If the generalized table is not empty, it can be divided into a header and a footer, otherwise, the generalized table can be uniquely determined for the header and footer. For a non-empty generalized list: call the first element the header of L, and the list composed of other elements is called the tail of LS:
- Generalized table storage structure
- Since the data elements in the generalized table can have different structures, it is difficult to express the generalized table with a sequential structure. Generally, how to set the linked list nodes in the linked list storage method? The data elements in the generalized table may be single elements (atoms) or sub-tables, which requires two kinds of nodes: one is the table node to represent the generalized table; One is a single element node, used to represent a single element (atom)
- Single element node
- Table node
- Schematic diagram of the storage structure of the generalized table