#include
#include
#define LIST_INIT_SIZE 100//线性表存储空间的初始分配量
#define LISTINCREMENT 10//线性表存储空间的分配增量
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
typedef int ElemType;
typedef struct{
ElemType elme;//存储空间基地址
int length;//当前长度
int listsize;//当前分配的存储容量
}SqList;
Status ListInsert_Sq(SqList &L,int i,ElemType e)
{
if(iL.length+1) return ERROR;
if(L.length>=L.listsize){
newbase=(ElemType)realloc(L.elem,
(L.listsize+LISTINCREMENT)*sizeof(ElemType));
if(newbase==0)exit(OVERFLOW);
L.elem=newbase;
L.listsize+=LISTINVREMENT;
}
q=&(L.elem[i-1]);
for(p=&(L.elem[L.length-1]);p>=q; --p) (p+1)=*p;
*q=e;
++L.length;
return OK;
}
Status InitList_Sq(SqList &L)
{
L.elem=(ElemType)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!L.elem)exit(OVERFLOW);
L.length=0;
L.listsize=LIST_INIT_SIZE;
return OK;
}
void main()
{
SqList L;
InitList_Sq(L);
ListInsert_Sq(L,1,5);
return 0;
}

求大神看看这个程序怎么弄 线性表的插入算法 老显示有错误
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- threenewbee 2019-03-12 00:40关注
typedef int Status; typedef int ElemType; 这里不能有分号 否则 Status InitList_Sq(SqList &L) 变成了 int; InitList_Sq(SqList &L) 下面的错误提示是main函数返回值应该是int,这是C99规定的,你用了void,这是很久以前不标准的写法。 Status InitList_Sq(SqList &L) 这种引用的写法,是C++的,C不支持
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报