Data Structures: Generalized tables

Source: Internet
Author: User
Tags data structures

Concepts: Arrays and generalized tables can be thought of as extensions of linear tables in the following meanings, and the data elements in the table are themselves a data structure.

Generalized tables can also be regarded as the generalization of linear tables.

(1) The elements of a generalized table can be child tables, and the elements of a child table can also contain child tables.

(2) The list can be shared by other lists.

(3) A list can be a recursive table, which means that the list can also be its own child table.

Since the data elements in a generalized table can have different structures, a chained storage structure is used, and a node represents a data element.

I am here to construct the generalized table nodes as follows: (may be inconsistent with the book but I am more accustomed to the same function)

Three fields: Flag field (flag of element type, 0 for head node, 1 for int,2 to represent char,3 for child table)

Data field (according to the Flag field and the data is different, if it is the head node, then put the pointer count)

Pointer field (points to next node)

typedef enum[head = 0,int = 1,char = 2,list = 3] nodetype;//represents a type with an enumeration

struct gennode;//first declare the struct

typedef Union

{

int ref;

int intinfo;

Char Charinfo;

gennode* hlink;

}ELEMTYPE;//uses a consortium, which saves space.

struct Gennode

{

NodeType Utype;

Elemtype value;

Gennode *tlink;

}

With such a structure, the next

(1) Get the head node.

(2) Get the common knot.

(3) Try to initialize the generalized table according to the corresponding elements

(4) To realize the operation of adding and deleting and checking and changing

(5) Note that memory leaks do not occur

Can be used to assign a value to a string


For the construction of a generalized table, the way I learned it is to construct it by class, and to think that it is possible to use a struct if it is not.


A generalized table can be initialized by a constructor, and the parameter form can be a string as described above.


Then the next problem only exists in how to break apart the string and then as a node of the data to construct the generalized table we need, because we can learn the generalized table, I think the list should be very skilled, the chain list of the structure of adding what I did not say, the only possible difficulty is that the child table recursive set up, But know is to use recursion and then to the top of the good, if you want to test the output of the sub-table will also be recursive to output the best, so the generalized table compared to the previous data structure is actually different is just that we use the recursion.













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.