[求救]顺序表问题2
1.实现顺序表的各种基本操作。#define Maxsize 100
#include <stdio.h>
typedef int elemtype;
typedef struct sqnode
{elemtype elem[Maxsize];
int len; /*注意这里的len代表的含义与书本上last的区别*/
}sqlist;
void create_sqlist(sqlist *L)
{int i;
printf("Please input the len of the sqlist:");
scanf("%d",&(*L).len);
printf("Please input the every element of the sqlist:");
for(i=0;i<(*L).len;i++)
scanf("%d",&(*L).elem[i]);
printf("Output the every element of the sqlist:");
for(i=0;i<(*L).len;i++)
printf("%d ",(*L).elem[i]);
printf("\n");
}
void access_sqlist(sqlist *L,int i)
{if((i<0)||(i>(*L).len-1))
printf("The place is not correct!\n");
else
printf("%d\n",(*L).elem[i]);
}
void before_after_sqlist(sqlist *L,int i)
{if((i<0)||(i>(*L).len-1))
printf("The place is not correct!\n");
else if(i==0)
printf("%d\n",(*L).elem[i+1]);
else if(i==(*L).len-1)
printf("%d\n",(*L).elem[i-1]);
else if((i>0)&&(i<(*L).len-1))
printf("%d,%d\n",(*L).elem[i-1],(*L).elem[i+1]);
}
void search_sqlist(sqlist *L,int s_key)
{int m;
for(m=0;m<(*L).len;m++)
{if((*L).elem[m]!=s_key)
continue;
else
{printf("Seaching is seccessful!\n");
printf("The place of the search key is:%d\n",m);
break;
}
}
if(m>=(*L).len)
printf("The sqlist has no the s_key!\n");
}
void delete_sqlist(sqlist *L,int i)
{int n;
(*L).len--;
for(n=i;n<(*L).len;n++)
(*L).elem[n]=(*L).elem[n+1];
printf("Output the every element of the sqlist:");
for(i=0;i<(*L).len;i++)
printf("%d ",(*L).elem[i]);
printf("\n");
}
void insert_sqlist(sqlist *L,int i,int e)
{int m;
(*L).len++;
for(m=(*L).len-1;m>=i;m--)
(*L).elem[m+1]=(*L).elem[m];
(*L).elem[i]=e;
printf("Output the every element of the sqlist:");
for(i=0;i<(*L).len;i++)
printf("%d ",(*L).elem[i]);
printf("\n");
}
show_sqlist( )
{
}
main()
{ sqlist *L;
int i,e;
clrscr();
printf("\nfunction:create_sqlist\n");
create_sqlist(L);
show_sqlist(L);
printf("\nfunction:access_sqlist\n");
printf("Please input the position:");
scanf("%d",&i);
access_sqlist(L,i);
show_sqlist(L);
printf("\nfunction:before_after_sqlist\n");
printf("Please input the position:");
scanf("%d",&i);
before_after_sqlist(L,i);
show_sqlist(L);
printf("\nfunction:search_sqlist\n");
printf("Please input the search key:");
scanf("%d",&e);
search_sqlist(L,e);
show_sqlist(L);
printf("\nfunction:delete_sqlist\n");
printf("Please input the delete position:");
scanf("%d",&i);
delete_sqlist(L,i);
show_sqlist(L);
printf("\nfunction:insert_sqlist\n");
printf("Please input the insert position:");
scanf("%d",&i);
printf("Please input the insert element:");
scanf("%d",&e);
insert_sqlist(L,i,e);
show_sqlist(L);
1。写出每个函数的功能:
create_sqlist;
access_sqlist ;
before_after_sqlist;
search_sqlist;
delete_sqlist ;
insert_sqlist;
2。将上述顺序表中表元素的函数show_sqlist补充完整;