-
Notifications
You must be signed in to change notification settings - Fork 0
/
SqList.c
88 lines (78 loc) · 1.57 KB
/
SqList.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
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
81
82
83
84
85
86
87
88
/*
* =====================================================================================
*
* Filename: SqList.c
*
* Description:
*
* Version: 1.0
* Created: 11/29/2014 10:00:51 AM
* Revision: none
* Compiler: gcc
*
* Author: 张世龙 (mn), [email protected]
* Company: free
*
* =====================================================================================
*/
#include "Public.h"
#include "SqList.h"
void InitList(SqList *list)
{
assert(list);
list->length = 0;
}
int ListEmpty(SqList *list)
{
assert(list);
return list->length == 0;
}
void ClearList(SqList *list)
{
list->length = 0;
}
int GetElem(SqList *list,int i,ElemType *e)
{
assert(list && e);
if(list->length < i)
return ERROR;
*e = list->data[i-1];
return SUCCESS;
}
int LocateElem(SqList *list,ElemType *e)
{
assert(list && e);
for(int i=0;i<list->length;++i){
if(list->data[i] == *e){
return i+1;
}
}
return 0;
}
int ListInsert(SqList *list,int i,ElemType *e)
{
assert(list && e);
if(list->length == MAXSIZE || i < 1)
return ERROR;
for(int index=list->length-1;index>=i-1;--index)
list->data[index+1] = list->data[index];
list->data[i-1] = *e;
list->length++;
return SUCCESS;
}
int ListDelete(SqList *list,int i,ElemType *e)
{
assert(list && e);
if(list->length == MAXSIZE || i < 1)
return ERROR;
*e = list->data[i-1];
for(int index=i;index<list->length;++index)
list->data[index-1] = list->data[index];
list->length--;
return SUCCESS;
}
int ListLength(SqList *list)
{
assert(list);
return list->length;
}