#include
#define MAXSIZE 10000 typedef int ElemType; typedef struct list {
ElemType *elem; int listsize; int length;
}Sqlist;
void initlist_sq(Sqlist *L)//创建一个链表 {
L -> elem = (ElemType *)malloc(MAXSIZE*sizeof(ElemType)); if(! L -> elem) exit(0); }
L -> length = 0;
L -> listsize = MAXSIZE;
void insert_sq(Sqlist *L,int n,ElemType x)//插入元素(n为插入的位置,x为插入的值) { }
void creat_sq(Sqlist *L)//输入链表的值 {
int tablen,i = 0;
ElemType temp; printf(\ scanf(\
int i;
if(n < 0 || n > L -> length + 1) {
printf(\ return ;
}
for(i = L-> length;i >= n;i--) { }
L -> elem[i + 1] = L -> elem[i];
L -> elem[i] = x;//L -> elem[i - 1] = x; L -> length++;
//printf(\
printf(\/*do { scanf(\ insert_sq(L,i,temp);
i++;
}while((i < tablen) && (i < L -> listsize ));*/ while(i < tablen) { }
scanf(\L -> elem[i] = temp; L -> length++; i++;
}
void display_sq(Sqlist *L)//输出当前链表的值 {
int i; i = 0; do
{ printf(\}while(++i < L -> length);
printf(\
}
int Search_sq(Sqlist *L,ElemType x)//在当前链表中查找x {
int i; i = 0; do { }
while(++i < L -> length); return 0;
}
ElemType Search_sq_byV(Sqlist *L,int n)//(输入位置n,查找该位置的值) { }
return L -> elem[n - 1]; if(L -> elem[i] == x) {
return i + 1; }
void delete_sq(Sqlist *L,int pos)//删除 pos为删除的位置 {
do {
L->elem[pos - 1] = L->elem[pos]; pos++;
}
while(pos < L -> length); L -> length--;
}
int main(void) {
while(1) {
cmd=getchar(); switch(cmd) {
case 'C': case 'c':
Sqlist L1; ElemType temp; char cmd;
int i=0;
initlist_sq(&L1);
printf(\TE,P=DISPLAY,I=INSERT,S=SEARCH,D=DELETE\\n \
creat_sq(&L1);
printf(\T,P=DISPLAY,I=INSERT,S=SEARCH,D=DELETE \\n\
break; case 'I':
case 'i': printf(\
break; case 'S': case 's':
scanf(\
printf(\scanf(\
insert_sq(&L1,i,temp);//insert_sq(&L1,i - 1,temp); printf(\
printf(\T,P=DISPLAY,I=INSERT,S=SEARCH,D=DELETE \\n\
printf(\
scanf(\
if(Search_sq(&L1,temp)) { printf(\该数在链表中的位置是第%d}
else { printf(\该数在链表中不存在\\n\}
个.\\n\
Search_sq(&L1,temp));
printf(\T,P=DISPLAY,I=INSERT,S=SEARCH,D=DELETE \\n\
break;
case 'V': case 'v':
printf(\scanf(\
if(i >= 1 && i <= L1.length) {
printf(\在%d位置的值为: %d \\n\
} else { printf(\该位置没有值存在!\}
printf(\T,P=DISPLAY,I=INSERT,S=SEARCH,D=DELETE \\n\
break; case 'D':
case 'd': printf(\
scanf(\delete_sq(&L1,i);
if(i >= 0 && i <= L1.length) { printf(\该位置的值已经删除!\\n\} else { }
printf(\该位置不存在!\\n\
}
printf(\T,P=DISPLAY,I=INSERT,S=SEARCH,D=DELETE \\n\
}
break; case 'P': case 'p': display_sq(&L1);
break; case 'X': case 'x':
free(L1.elem); return 1;
printf(\T,P=DISPLAY,I=INSERT,S=SEARCH,D=DELETE \\n\
default:break;
}
return 1;