在里面创建第一个表,第二个表,都可以实现,为啥一创建第三个就运行错误……
代码如下:只要一加入【】部分的代码,就会出现“顺序合并表.exe已停止工作”这个框框,如果删掉【】那部分代码就没事...为啥啊到底 QAQ
#include
#include
#include
#define MaxSize 500
#define Extra 100
typedef int ElementType;
typedef struct{
ElementType *a;
int lenght;
int capacity;
}Seqlist;
typedef Seqlist* Sq;
Sq InitList(Seqlist *p)
{
p->a = (ElementType *)malloc(sizeof(ElementType)*MaxSize);
p->lenght = 0;
p->capacity = MaxSize;
return(p);
}
int InsertList(Sq p,int i,ElementType e)
{
if(i
{
printf("error");
}
else
{
if(i==p->lenght)
{
p->a[i]=e;
}
else
{
int j;
for(j=p->lenght;j>=i;j--)
{
p->a[j-1]=p->a[j];
}
}
p->a[i]=e;
p->lenght +=1;
}
}
int PrintList(ElementType e)
{
printf("%d, ",e);
}
void TraverseList(Sq p,int (*print)(ElementType e))
{
int i=0;
for(i=0;ilenght;i++)
{
print(p->a[i]);
}
}
int main()
{
Seqlist LA,LB;
Sq A,B;
*A =LA;
*B =LB;
InitList(A);
InitList(B);
int i,e;
InsertList(A,0,1);
InsertList(A,1,5);
InsertList(A,2,9);
InsertList(B,0,2);
InsertList(B,1,10);
【Seqlist listc;
Sq lc;
InsertList(lc,0,0);】
printf("顺序表A的元素如下:\n");
TraverseList(A,PrintList);
printf("\n");
printf("顺序表B的元素如下:\n");
TraverseList(B,PrintList);
printf("\n");
printf("-----------------------\n");
printf("请选择操作:\n");
printf("1.顺序合并两表:\n");
printf("2.倒置合并两表: \n");
printf("-----------------------\n");
}