1 #include<iostream>
2
3 using namespace std;
4
5 //线性表的顺序存储结构
6
7 #define MAXSIZE 100//数组的最大值
8 #define elemtype int//数据元素的类型
9 #define OK 1
10 #define ERROR 0
11
12 #define TURE 1
13 #define FALSE 0
14 typedef int statues;
15
16 //顺序存储的线性表的数据结构
17 typedef struct{
18 elemtype data[MAXSIZE];
19 int length;
20 }Sqlist;
21
22 //初始化操作
23 //初始化一个线性表,返回1.
24 bool InitList(Sqlist *L)
25 {
26 L->length=0;
27 return OK;
28 }
29
30 //将线性表清空
31 //函数成功则返回1
32 bool clearlist(Sqlist *L)
33 {
34 L->length=0;
35 return 1;
36 }
37
38 //判断是否为空
39 //若为空则返回值为1否则为0
40 bool isempty(Sqlist L)
41 {
42 if(L.length!=0)
43 return 0;
44 else
45 return 1;
46 }
47
48
49 //返回操作
50 //返回线性表L的第i个元素给e,成功则返回1否则为0
51 bool getelem(Sqlist L,int i,elemtype *e)
52 {
53 if(L.length==0)
54 return FALSE;
55 if(i<1||i>L.length)
56 return FALSE;
57 *e=L.data[i-1];
58 return OK;
59 }
60
61 //查找操作
62 //查找元素e在线性表L中的位置,查找成功则返回元素e的位置,否则返回0
63 int locationlist(Sqlist L,elemtype e)
64 {
65 if(L.length==0)
66 return 0;
67 for(int i=0;i!=L.length;++i)
68 {
69 if(L.data[i]==e)
70 return i+1;
71 }
72 return 0;
73 }
74
75 //插入元素
76 //将元素e插入到线性表L中的第i个元素之前,若成功则返回1,否则返回0
77 bool insertlist(Sqlist *L,int i,elemtype e)
78 {
79
80 if(L->length==MAXSIZE)
81 return 0;
82 if(i<1||i>L->length+1)
83 return 0;
84 if(i<=L->length)
85 {
86 for(int j=L->length-1;j!=i-2;--j)
87 L->data[j+1]=L->data[j];
88 }
89 L->data[i-1]=e;
90 L->length++;
91 return 1;
92 }
93
94
95
96
97 int main()
98 {
99
100 system("pause");
101 return 1;
102 }