-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy path6-2_顺序表操作集 (20).c
50 lines (47 loc) · 926 Bytes
/
6-2_顺序表操作集 (20).c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
List MakeEmpty()
{
List L = (List) malloc(sizeof(struct LNode));
L->Last = -1;
return L;
}
Position Find( List L, ElementType X )
{
for (Position i = 0; i <= L->Last; i++) {
if (X == L->Data[i]) return i;
}
return ERROR;
}
bool Insert( List L, ElementType X, Position P )
{
if (L->Last + 1 == MAXSIZE)
{
printf("FULL");
return false;
}
if (P < 0 || P > L-> Last+1)
{
printf("ILLEGAL POSITION");
return false;
}
for (Position i = L->Last; i >= P; i--)
{
L->Data[i+1] = L->Data[i];
}
L->Data[P] = X;
L->Last += 1;
return true;
}
bool Delete( List L, Position P )
{
if (P < 0 || P > L-> Last)
{
printf("POSITION %d EMPTY", P);
return false;
}
for (Position i = P; i < L->Last; i++)
{
L->Data[i] = L->Data[i+1];
}
L->Last -= 1;
return true;
}