-
Notifications
You must be signed in to change notification settings - Fork 0
/
SequenceList.cpp
80 lines (65 loc) · 1.24 KB
/
SequenceList.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// Created by 何翔宇 on 2021/8/19.
//
#ifndef SEQUENCELIST_C
#define SEQUENCELIST_C
#include "SequenceList.h"
Status InitList_Sq(SqList *L)
{
(*L).elem=(LElemType_Sq*) malloc(LIST_INIT_SIZE*sizeof(LELEMTYPE_SQ));
if(!(*L).elem)
exit(OVERFLOW);
(*L).length=0;
(*L).listsize=LIST_INIT_SIZE;
return OK;
}
void ClearList_Sq(SqList *L)
{
(*L).length=0;
}
void DestroyList_Sq(SqList *L)
{
free((*L).elem);
(*L).elem=NULL;
(*L).length=0;
(*L).listsize=0;
}
Status ListEmpty_Sq(SqList L)
{
return L.length==0?TRUE:FALSE;
}
int ListLength_Sq(SqList L)
{
return L.length;
}
Status GetElem_Sq(SqList L,int i,LElemType_Sq *e)
{
if(i<1||i>L.length)
return ERROR;
else
*e=L.elem[i-1];
return OK;
}
int LocateELem_Sq(SqList L,LElemType_Sq e,Status(Compare)(LElemType_Sq,LElemType_Sq))
{
int i=1;
while(i<L.length&&!Compare(e,L.elem[i-1]))
++i;
if(i<=L.length)
return i;
else
return 0;
}
Status PriorElem_Sq(SqList L,LElemType_Sq cur_e,LElemType_Sq *pre_e)
{
int i=1;
if(L.elem[0]!=cur_e)
{
while(i<L.length&&L.elem[i]!=cur_e)
++i;
if(i<L.length)
{
*pre_e=L.elem
}
}
}