线性表出现错误无法运行

img


求大佬解答,大学编写线性表,编完后显示出这个东西

if(L.elem==MAXSIZE)像这里应该是L.length和MAXSIZE做比较

由于你的book结构沒有重载==操作符,所以写成
book b1,b2;
if(b1==b2)会报现在的错误

#include
#include
#include
#include
using namespace std;
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status; //Status 是函数返回值类型,其值是函数结果状态代码。
typedef int ElemType; //ElemType 为可定义的数据类型,此设为int类型

#define MAXSIZE 100 //顺序表可能达到的最大长度
struct Book {
string id;//ISBN
string name;//书名
double price;//定价
};
typedef struct {
Book *elem; //存储空间的基地址
int length; //当前长度
} SqList;

Status InitList_Sq(SqList &L) { //算法2.1 顺序表的初始化
L.elem=new Book[MAXSIZE]; //为顺序表分配一个大小为MAXSIZE的数组空间
if(!L.elem) exit(OVERFLOW); //储存失败退出
L.length=0; //设计空表长度为0
return OK;
}

Status GetElem(SqList L, int i, Book &e) {//算法2.2 顺序表的取值
if(i<1||i>L.length) return ERROR; //判断i的值是否符合要求长度
e=L.elem[i-1]; //数组L.elem[i-1],储存第i个数据
return OK;
}

int LocateElem_Sq(SqList L, double e) { //算法2.3 顺序表的查找
int i;
for(i=0;i<L.length;i++)
if(L.elem[i]==e) return i+1; //查找成功返回值为i+1
return 0; //查找失败返回值0
}

Status ListInsert_Sq(SqList &L, int i, Book e) { //算法2.4 顺序表的插入
int j;
if((i<1)||(i>L.length+1)) return ERROR; //插入的位置i不合法
if(L.elem==MAXSIZE) return ERROR; //数组储存空间已满无法插入
for(j=L.length-1;j>=i-1;j--)
L.elem[j]=L.elem[j+1]; //插入位置后的元素后移
L.elem[i-1]=e; //将元素e插入第i个位置
++L.length; //表长加一
return OK;
}

Status ListDelete_Sq(SqList &L, int i) { //算法2.5 顺序表的删除
int j;
if((i<1)||(i>L.length)) return ERROR; //删除的位置i不合法
for(j=i;j<=L.length-1;j++)
L.elem[j]=L.elem[j-1]; //被删除元素之后的元素前移
--L.length; //表长减一
return OK;
}

int main() {
SqList L;
int i = 0, temp, a, c, choose;
double price;
Book e;
string head_1, head_2, head_3;
cout << "1. 建立\n";
cout << "2. 输入\n";
cout << "3. 取值\n";
cout << "4. 查找\n";
cout << "5. 插入\n";
cout << "6. 删除\n";
cout << "7. 输出\n";
cout << "0. 退出\n\n";

choose = -1;
while (choose != 0) {
    cout << "请选择:";
    cin >> choose;
    switch (choose) {