主题:线性表的删除问题,主函数出错
嗯,本人对主函数的编写一直有问题。
这次做线性表的删除问题又死掉了。
忘哪位大侠帮忙指点下
#include<stdio.h>
#define maxsize 100
typedef struct
{
int data[maxsize];
int last;
}sqlist;
sqlist initiate(sqlist la)
{la.last=0;
return la;
}
sqlist setupsqlist ()
{ sqlist sq;
int i=0,n;
scanf("%d",&n);
while(n!=32767&&i<maxsize)
{sq.data[i++]=n;
scanf("%d",&n);
}
sq.last=i;
}
sqlist del(sqlist sq,int i)
{ if(i<1 && i>sq.last )
printf("出错。请重新输入");
int j;
for(j=i;j<sq.last-1;j++)
{sq.data[j-1]=sq.data[j];
sq.last=sq.last-1;
return sq;
}
void main()
{
int i,j;
sqlist sq;
sq=initiste(sq);
sq=setupsqlist();
scanf("%d",&i);
sq=del(sq,i);
for(j=0;j<sq.last-1;j++)
printf("%d",sq.data[j]);
}
这次做线性表的删除问题又死掉了。
忘哪位大侠帮忙指点下
#include<stdio.h>
#define maxsize 100
typedef struct
{
int data[maxsize];
int last;
}sqlist;
sqlist initiate(sqlist la)
{la.last=0;
return la;
}
sqlist setupsqlist ()
{ sqlist sq;
int i=0,n;
scanf("%d",&n);
while(n!=32767&&i<maxsize)
{sq.data[i++]=n;
scanf("%d",&n);
}
sq.last=i;
}
sqlist del(sqlist sq,int i)
{ if(i<1 && i>sq.last )
printf("出错。请重新输入");
int j;
for(j=i;j<sq.last-1;j++)
{sq.data[j-1]=sq.data[j];
sq.last=sq.last-1;
return sq;
}
void main()
{
int i,j;
sqlist sq;
sq=initiste(sq);
sq=setupsqlist();
scanf("%d",&i);
sq=del(sq,i);
for(j=0;j<sq.last-1;j++)
printf("%d",sq.data[j]);
}