|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
为什么运行结果是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[u+1]=L.elem[u];
L.elem[j-1]=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;看清楚,这条件永远成立! 应该是==
|
|