帮我看一下线性表的插入代码
为什么运行结果是0? 是线性表的插入代码。。。
#include<iostream>
#include<stdlib.h>
using namespace std;
#define OK 1
#define ERROR 0
#define MAXSIZE 100
typedef int Status;
typedef int ElemType;
typedef struct
{
ElemType *elem;
int length;
}SqList;
Status InitList_Sq(SqList &L){
//构造一个空的线性表L
L.elem = (ElemType *)malloc(MAXSIZE * sizeof(ElemType));
if(!L.elem)
exit(1); //存储分配失败
L.length = 0;//空表长度为0
return OK;
}
Status ListInsert(SqList &L,int j,ElemType e) //顺序表的插入
{
if((j<1)||(j>L.length+1))
return ERROR;
if(L.length=MAXSIZE)
return ERROR;
for(int u=L.length-1;u>=j-1;u--)
L.elem=L.elem;
L.elem=e;
++L.length;
cout<<e<<endl;
return OK;
}
int main()
{
SqList L;
InitList_Sq(L);
ListInsert(L,1,2);
ElemType e=ListInsert(L,1,2);
cout<<e<<endl;
} if(L.length=MAXSIZE) return ERROR;看清楚,这条件永远成立! 应该是== fzquchs 发表于 2016-3-19 20:32
if(L.length=MAXSIZE) return ERROR;看清楚,这条件永远成立! 应该是==
谢谢啦 {:10_256:} 感谢分享
页:
[1]