Current location - Training Enrollment Network - Books and materials - How to establish 1 linear table in data structure?
How to establish 1 linear table in data structure?
The code for establishing the sequence table is as follows:

The order table L consists of array element a[0..n- 1]. Put each element in a into the sequence table in turn, and assign n to the length field of the sequence table. The algorithm is:

void create list(SqList * & amp; l,ElemType a[],int n){

int i=0,k = 0;

l =(SqList *)malloc(sizeof(SqList)); //Allocate space for storing linear tables

While (I & ltn){

l-& gt; data[k]= a[I];

k++; i++;

}

l-& gt; Length = k;; //Set the actual length of the linear table to k (that is, the length n of A)

}

Extended data

The characteristics of linear table:

1. For the same linear table, although the value of each data element is different, it must have the same data type;

2. There is a linear or one-to-one logical relationship between data elements.

3. The first data element has no predecessor, and this data element is called the starting node;

4. The last data element has no successor, and this data element is called a terminal node;

5. Except the first and last data elements, other data elements have only one preamble and one successor.

Abstract data type description of linear table

The basic operation is as follows:

Empty operation of 1. linear table clear (): set the existing linear table as an empty table.

2. linear table empty operation isEmpty (): judge whether the linear table is empty, and if so, return true;; Otherwise, the return is false.

3. Find the length of the linear table operation length (): Find the number of data elements in the linear table and return their values.