顺序表的就地逆置
#include<stdio.h>#include<stdlib.h>
#define Maxsize 10
typedef struct
{
int *elem;
int length;
}sqlist;
void reverseSQ(sqlist *l)
{
int low=0;
int high=l->length-1;
int buf,i;
for(i=0;i<high/2;i++)
{
buf=l->elem[low];
l->elem[low]=l->elem[high];
l->elem[high]=buf;
low++;
high--;
}
}
int main(void)
{
sqlist *l;
int a,i=0;
l->elem=(int *)malloc(Maxsize*sizeof(int));
if(!l->elem)
{
printf("Malloc eroor!\n");
return 0;
}
l->length=0;
printf("Please input below 10 integer into the sqlist\n");
printf("Type -1 for stopping input\n");
scanf("&d",&a);
while(a!=-1&&i<=9)
{
l->elem[i]=a;
l->length++;
i++;
scanf("%d",&a);
}
printf("The content of the sqlist are:\n");
for(i=0;i<l->length;i++)
{
printf("%3d",l->elem[i]);
}
printf("\n");
reverseSQ(l);
printf("The content of the reversed sqlist are\n");
for(i=0;i<l->length;i++)
{
printf("%3d",l->elem[i]);
}
printf("\n");
return 0;
}
那位高手给指点一二,怎么一运行就崩溃啊,编译没有错误,哪里错了,希望给出清楚解答,急啊!!!!!!