-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist - sequential.c
66 lines (66 loc) · 1.41 KB
/
list - sequential.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
#include <stdio.h>
#include <string.h>
#define MAXSIZE 20
typedef struct {
int list[MAXSIZE];
int length;
} list;
int insert_list(list *l,int site,int insert_object)
{
char a[]="插入位置越界";char b[]="数组已满";char c[]="OK";
if (site>l->length||site<0)
{
printf("%s\n", a);
return 0;
}
if(l->length==MAXSIZE)
{
printf("%s\n", b);
return 0;
}
if (site!=l->length){
int z=l->length-site;
for (int i = 0; i < z; i++)
{
l->list[l->length-i]=l->list[l->length-1-i];
}
}
l->list[site]=insert_object;
l->length++;
printf("%s\n", c);
return 1;
}
int del_list(list *l,int site){
char a[]="删除位置越界";char e[]="删除成功";
if (site>l->length-1||site<0)
{
printf("%s\n", a);
return 0;
}
int b=site;
for (int i = 0; i < l->length-site; i++)
{
l->list[b]=l->list[b+1];b++;
}
l->length--;
printf("%s\n",e);
return 1;
}
int query(list *l,int site){
int a;a=l->list[site];
return a;
}
int main(void){
list l = {{1,2,3,4,5,6,7,8,9},9};
int a= query(&l,2);
printf("%d\n",a);
printf("The updated list is: ");
for (int i = 0; i < l.length; i++) {
printf("%d ", l.list[i]);
}
}
/*
#Attention
1、注意通过长度查看线性表满了没有,是不是空表
2、结束后长度要变化
*/