用C++实现顺序表的问题!!!

来源:百度知道 编辑:UC知道 时间:2024/06/02 07:04:00
“将L重置为空表”处出了问题 请问如何修改????

#include<iostream.h>
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10

struct List
{
int length;
int listsize;
List *elem;
};

int InitList(List &L)//构造一个空的线性表L
{
L.elem=new List;
if (!L.length) return 0;
L.length=0;
L.listsize=LIST_INIT_SIZE;
return 1;
}

int DestroyList(List &L)//销毁线性表L
{
delete(L.elem);
L.elem=NULL;
L.length=0;
L.listsize=0;
}

int ClearList(List &L)//将L重置为空表
{
if(!L.length) return 0;
for(int i=0;i<=L.length-1;i++)
{
if(L.elem[i]!=0)L.elem[i]=0;//35行
}
return 1;
}

错误提示:
C:\Documents and Settings\Administrator\桌面\数据结构作业\顺序表相关操作.cpp(35) : error C2676: binary '!=' : 'struct List' does not define this operator or a conversion to a type acceptable to the predefined op

帮你改好了:

#include<iostream.h>
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10

struct List
{
int length;
int listsize;
int *elem; //这里不同
};

int InitList(List &L)//构造一个空的线性表L
{
L.elem=new int; //开辟空间
if (!L.length) return 0;
L.length=0;
L.listsize=LIST_INIT_SIZE;
return 1;
}

int DestroyList(List &L)//销毁线性表L
{
delete(L.elem);
L.elem=NULL;
L.length=0;
L.listsize=0;
return 1;
}

int ClearList(List &L)//将L重置为空表
{
if(!L.length) return 0;
else //这里有个else 严密性
for(int i=0;i<=L.length-1;i++)
{
if(L.elem[i]!=0)L.elem[i]=0;//35行
}
return 1;
}
int main()
{
return 0;
}

我写的 你自