线形表 帮忙看看哪错了
插入以后,输出不对。#include"stdio.h"
#define Maxsize 20
typedef int elemtype;
typedef struct{
elemtype data[Maxsize];
int length;
}sqlist;
typedef struct node{
elemtype data;
struct node *next;
}lnode;
typedef lnode * linklist;
main()
{void list_seq();
void list_link();
int i=1,ch;
/*clrscr();*/
while(i)
{ printf("\n\t\t***********************************");
printf("\n\t\t* 1---------seqlist *");
printf("\n\t\t* 2---------linklist *");
printf("\n\t\t* 0---------return *");
printf("\n\t\t***********************************");
printf("\n please input your choice:");
scanf("%d",&ch);
if(ch==1)
list_seq();
else if(ch==2)
list_link();
else if(ch==0)
return;
else
printf("\n\tinput error,please input again");
}
}
void list_seq()
{void initlist_sq(sqlist *s);
void creat_sq(sqlist *);
void insert_sq(sqlist *,int i,elemtype x);
void delete_sq(sqlist *,int);
int length_sq(sqlist*);
elemtype getelem_sq(sqlist*,int);
void output_sq(sqlist *);
sqlist sq;
int ch1=1;
int ch2;
while(ch1)
{/*clrscr();*/
printf("\n\t\t***********************************");
printf("\n\t\t* 1---------intilist *");
printf("\n\t\t* 2---------creatlist *");
printf("\n\t\t* 3---------insert *");
printf("\n\t\t* 4---------delete *");
printf("\n\t\t* 5---------length *");
printf("\n\t\t* 6---------getelement *");
printf("\n\t\t* 7---------outputelem *");
printf("\n\t\t* 0---------return *");
printf("\n\t\t***********************************");
printf("\n please input your choice:");
scanf("%d",&ch2);
switch(ch2)
{case 1:
{initlist_sq(&sq); break;}
case 2:
{creat_sq(&sq); break;}
case 3:
{int i;elemtype x;
printf("\n\t\t please input the position of insert-element:");
scanf("%d",&i);
printf("\n\t\t please input the value of insert-element:");
scanf("%d",&x);
insert_sq(&sq,i,x); break;
}
case 4:
{int i;
printf("\n\t\t please input the position of delete-element:");
scanf("%d",&i);
delete_sq(&sq,i); break;
}
case 5:
{int len;
len=length_sq(&sq);
printf("\nThe length of sq-list is %d:",len);
break;
}
case 6:
{elemtype x;int i;
printf("\n\t\t please input the position of get-element:");
scanf("%d",&i);
x=getelem_sq(&sq,i);
printf("\n element value is:",x);
break;
}
case 7:
{output_sq(&sq); break;}
case 0:
return;
defult:printf("\n\ninput error,please input again");
}
}
}
void initlist_sq(sqlist *s)
{s->length=0;}
void creat_sq(sqlist *s)
{printf("\n creat-list");
s->data[0]=3;
s->data[1]=45;
s->data[2]=32;
s->length=3;
}
void insert_sq(sqlist *s,int i,elemtype x)
{int k;
printf("\ninsert position <=%d",s->length+1);
if(i<1||i>s->length+1) printf("\n position ERROR\n");
else{
for(k=s->length-1;k>=i-1;i--)
s->data[k+1]=s->data[k];
s->data[i-1]=x;
s->length++;printf("\n***** insert success*****\n");
}}
void delete_sq(sqlist *s,int i)
{printf("\ndelete");
s->data[i]=s->data[i+1];
}
int length_sq(sqlist *s)
{return(s->length);
}
elemtype getelem_sq(sqlist *s,int i)
{
return(s->data[i-1]);}
void output_sq(sqlist *s)
{int k;
printf("\n sqlist element is:");
for(k=0;k<s->length;k++)
printf("%d ",s->data[k]);
printf("\n");
}
void list_link()
{printf("\nlink");
}