qq_39276360 2017-09-17 13:00 采纳率: 0%
浏览 768

创建线性表并插入数值的时候总是失败,请大神指点

#include
#include
#include
#include
#define ok 1
#define error 0
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define True 1
#define false 0

typedef int Status;

typedef int ElemType;

typedef int ElemType;

typedef struct{
ElemType *elem;
int length;
int Listsize;
}List;

Status InitList(List &L,int n)//构建线性表
{
L.elem=(ElemType*) malloc(sizeof(ElemType)*LIST_INIT_SIZE); if ( !L.elem)exit(1);
L.length=0;
L.Listsize=LIST_INIT_SIZE;

printf("请输入数字:");
for (int i=0;i<n;i++)  
{ 
  scanf("%d",L.elem[i]);
  ++L.length; 


        if(L.length>=L.Listsize)  

        {  

        ElemType *newbase=(ElemType*)realloc(L.elem,(L.Listsize+LISTINCREMENT)*sizeof(ElemType));  

            if(!newbase)  

                exit(0);  

            L.elem=newbase;  

            L.Listsize+=LISTINCREMENT;  

        }  
    }
printf("初始化一个线性表\n");

return ok; 

}图片说明

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-09-17 14:42
    关注

    main函数在哪里,L本身分配内存了么?

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog