Describing data structures in C language

Source: Internet
Author: User

Learn computer, mainly from three aspects to start, among them, the first step is to learn a variety of languages, this is the first step, the various languages have a general understanding; then is the data structure, it is a core of the computer curriculum, but also a information calculation; In the end I think that is the algorithm, It is also the three of the most rare step, to learn computer, to do a good program element, these three steps is the most basic, and then in their foundation of the upper layer depth.

In the past year, I have a general understanding of the language of the computer, in the last some time, I self-study of the data structure, below, to talk about my self-study data structure of the view, in the next period of time someone pointed, then to correct the previous wrong view of the data structure.

Data structure is a relatively abstract thing, his task is from a variety of practical problems summed up, abstract the characteristics of objects, the relationship between objects, in the selection of appropriate data structure to organize, store and select the appropriate algorithm. One of the most important is a transformation of abstract thought, need to have an inductive thinking, in the beginner's time, I chose on the basis of the understanding of some of the more typical data structure, such as: Linear table, Team, money storage methods, and finally found some other things can be similar.

The C language description of the data structure can be divided into the following parts: Linear table, Team, money, generalized table, then the tree, graph, and finally recursion, string, lookup, sort. One of the more typical examples are maze, Hanoi, Access queue Huffman coding and so on.

A finite sequence of data elements with the same characteristics is present in two ways: sequential storage-sequential table, chain-type storage--linked list.

(i) Sequential table storage structure, using C language to run the classification of the basic operations:

Typedef char ElemType /*将字符性重新用ElemType来定义*/
#define MaxSize 99 /*用宏定义来定义MaxSize*/
Typedef struct
{
 ElemType elem[MaxSize]; /*定义一种为SqList的结构体类型*/
 Int length;
}SqList;

(1) Initialization of linear table

Void InitList(SqList *&L) /*将L定义为SqList类型*/
{
 L=(Sqlist *)malloc(sizeof(SqList)); /*在内存的动态区分配一个长度为n个
 L->length=0; 长为sizeof的连续空间*/
}

(2) Destroy the linear table

Void DestroyList(SqList *&L)
{
 Free(L); /*释放L的储存空间*/
}

(3) to determine whether the linear table is empty

Int ListEmpty(SqList *L)
{
 Return(L->length==0);
}

(4) To find the length of the linear table

Int ListLength(SqList *L)
{
 Return(L->length);
}

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.