Definition of abstract data type linear table
ADT List
{
数据对象
数据关系
基本操作
IniList(&L) //构建空表L
ListLength(&L) //求表L的长度
GetElem(L,i,&e) //去元素ai 由e返回ai
PriorElem(L,ce,&pre_e) //求ce的前驱,由pre_e返回
InsertElem(&L,i,e) //在元素ai之气插入新元素e
DeleteElem(&L,i) //删除第i个元素
EmptyList(L) //判断L是否为空表
}ADT List
Delete the i-th data element in table L as
L = (a1,a2,...,ai-1.ai..,an)
若删除 表中i的元素
记作 DeleteElem(&L,i)
若删除 表中x的元素
记作 DeleteElem(&L,x)
//
若ai = x 优先删除ai
Insert new element e before element ai
InsertElem(&L,i,e)
L= (ai,a2,....,ai-1,e,ai,...)
Search — Determine the element value (or the element whose data item value is e).
Given L = (a1,a2,…,ai,…an),
if the element e contains an ai = e, the search is successful, otherwise the search fails
5. Sorting-
Re-arrange the position of each element in the list according to the increasing (or decreasing) order of element value or a data item value. For
example: before sorting L = (90,60...)
after sorting: L = (10, 20, 30, 60)
6. Combine table La and table Lb into table Lc
into the set table sequence:
La = (2,14,20,45,80)
Lb = (8,10,19,20,22,85,90)
combined Table
Lc = (2, 8, 10, 14, 19, 20)
7. Copy table La into table Lb
La = (2,14,20,45,80)
Lb=(2,14,20,45,80)
The sequential representation of the linear table (sequential storage structure)
2.2.1 Sequential distribution----
store the data elements in the linear table in a group of storage units with consecutive addresses in the computer's memory. This distribution method is called sequential distribution , Or sequential image . The resulting storage structure or vector (one-dimensional array)
l For example,
linear table a = (30,40,10,55,24,80,66)
static one-dimensional array definition int a[11];
a[0] 30 a[1] 40 a[2] 55
The general form of sequence storage structure:
sequence number storage state storage address
1 a1 b
2 a2 b+q
i ai b+(i-1)*p
…
n an b+(n-1)*p
maleng b+ (maxleng- 1 )*p
b is the address of the first address/base address element ai
p -------------- The number of storage units occupied by 1 data element
maxleng ------------- Maximum length, a constant
The definition of linear table sequence structure in C language
#define maxleng 100
{
ElemType la[maxleng + 1]; / / 下标 0 1 maxleng
int length; //当前长度
int last; //an的位置
}
The definition of the sequential structure of the linear table in the C language (static allocation)
Example 2: The space occupied by the elements and the table length are merged into a structure type of the C language
#define maxleng 100
typedef struct
{
Elemtype elem[maxleng];//小标 0,1,... ,maxleng-1
int length;
}SqList;
SqList La;
Among them, typedef-alias definition, SqList-structure type name
La ---- structure type variable name
La.length ----- table length
La.elem[0] ------ a1
La.eleml[La, length-1] ----an
Table linear sequence structure defined in the C language (dynamically allocated)
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef struct
{ Lb - }