Data Structure tutorial 20th Class generalized table

Source: Internet
Author: User

Teaching Purpose: definition and storage structure of generalized table

Teaching emphases: The operation and significance of the generalized table

teaching Difficulties: Generalized table storage structure

Teaching Content:

Definition of a generalized table

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.

Second, the storage structure of the generalized table

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.