The generalized table is the generalization of the linear table, and the elements in the table can be another generalized table or its own.
Definition of a generalized table:
ADT glist{
Data objects: d={i=1,2,..., n>=0;ei (-atomset or EI (-glist,
Atomset to a data object}
Data relationship: R1={<ei-1,ei>|ei-1,ei (-d,2=<i<=n}
Basic operations:
Initglist (&L);
Action Result: Create an empty generalized table L
Createglist (&l,s);
Initial condition: S is the writing form string of the generalized table
Operation Result: The generalized table L created by s
Destroyglist (&L);
Initial Condition: Generalized table L existence
Operation Result: destruction of generalized table L
Copyglist (&t,l);
Initial Condition: Generalized table L existence
Operation Result: Generalized table T is copied by generalized table L
Glistlength (L);
Initial Condition: Generalized table L existence
Operation Result: To find the length of the generalized table L, that is, the number of elements
Glistdepth (L);
Initial Condition: Generalized table L existence
Operation Result: To find the depth of the generalized table L
Glistempty (L);
Initial Condition: Generalized table L existence
Operation Result: Judge whether the generalized table L is empty
GetHead (L);
Initial Condition: Generalized table L existence
Operation Result: Take the head of the generalized table L
GetTail (L);
Initial Condition: Generalized table L existence
Operation Result: Take the end of the generalized table L
INSERTFIRST_GL (&l,e);
Initial Condition: Generalized table L existence
Action Result: Insert Element e As the first element of the generalized table L
DELETEFIRST_GL (&l,&e);
Initial Condition: Generalized table L existence
Action Result: Deletes the first element of the generalized table L and returns its value with E
TRAVERSE_GL (L,visit ());
Initial Condition: Generalized table L existence
Operation Result: Traversing the Generalized table L, using function visit to process each element
}adt glist
Generalized table General notation: ls= (a1,a2,..., an)
Where LS is the name of the generalized table, n is its length, AI can be a single element is also a generalized table, called Atoms and children, respectively, when the generalized table is not empty, the first element is called the A1 of LS, and the generalized table of the other elements is the footer.
The storage representation of the tail-chain table of generalized table
typedef emnu{atom,list} Elemtag;
typedef struct glnode{
Elemtag tag;
union{
Atomtype Atom;
Struct{struct Glnode *HP,*TP;} ptr
}
}
The description of a, B, C, D, e Five generalized tables is as follows:
A= () A is an empty table with a length of zero
b= (e) List B only one atom e,b length is 1.
C= (A, (b,c,d)) The length of the list C is 2, and the two elements are atomic a and sub table (B,C,D)
d= (A,B,C) List D has a length of 3, three elements are lists, and obviously, after the child table's value is d= ((), (e), (A, (b,c,d))
E= (A,e) This is a recursive table, and its length is 2,e equivalent to an infinite list e= (A, (A, (a,...)))
The above five generalized tables use the storage structure of the above memory image as follows: