郁闷!输出竟然这样.....
大家帮忙看看,这个程序是实现顺序表删除从第i个元素开始起的k个元素.调试能运行,但输出竟然如此奇怪.源程序:
#define List_Init_Size 100
#define ListIncrement 10
typedef struct{
int *elem;
int length;
int listsize;
}Sqlist;
Sqlist L;
void Init_Sq(){
int i=0;
int tag=1;
L.elem=(int *)malloc(List_Init_Size*sizeof(int));
if(!L.elem) return 0;
L.length=0;
L.listsize=List_Init_Size;
printf("input integers to init the Sqlist:\n");
printf("please input 'n' when you complete\n");
while(tag==1)
{
scanf("%d",&L.elem[i++]);
if(L.elem[i]==110) tag=0;
L.length++;
}
L.length--;
}
void Delete_Sq(Sqlist L,int i,int k){
if(i<1||k<0||i+k>L.length)
return 0;
while((i+k-1)<L.length)
{L.elem[i-1]=L.elem[i+k-1]; i++;}
L.length-=k;
printf("After delete:\n");
for(i=0;i<L.length;i++)
printf("%3d",L.elem[i]);
}
void main()
{
Init_Sq();
Delete_Sq(L,2,3);
}