A_lemon_D 2017-03-25 11:28 采纳率: 0%
浏览 1056
已采纳

顺序线性表在c-free上的一些问题,在线等,挺急的!

在里面创建第一个表,第二个表,都可以实现,为啥一创建第三个就运行错误……
代码如下:只要一加入【】部分的代码,就会出现“顺序合并表.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");    

}

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-03-25 13:19
    关注

    Sq lc;
    lc没有初始化啊
    lc = malloc(...)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站