读书人

用C++写的一个创建顺序表并且初始化

发布时间: 2013-09-22 09:32:58 作者: rapoo

用C++写的一个创建顺序表,并且初始化一个顺序表的程序,为什么编译不通过?求大神帮忙看看问题出哪了.
#include <iostream>
using namespace std;

#define TURE 1
#define FALSE 0
#define ERROR 0
#define OK 1
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status;




#define LIST_INTT_SIZE 100
#define LISTINCREMENT 10




typedef struct {

char * elem;

int length;

int listsize;

}SqList;




Status Initlist_Sq(Sqlist &L)

{
L.elem=(char *)malloc(LIST_INIT_SIZE*sizeof(char));

if(!L.elem)exit(OVERFLOW);

L.length =0;

L.listsize=LIST_INIT_SIZE;



return OK;
}

  
   
int main ()

{

SqList L1;


Initlist_Sq(L1);


return 0;

}


[解决办法]
(Sqlist &L) // 大小写。。。
LIST_INIT_SIZE // #define LIST_INTT_SIZE 100 名字又错了
#include <cstdlib> // 缺少头文件
return OK; } // 这一块代码中可能还有全角下的字符

楼主太不细心了,不应该
[解决办法]

#include <iostream>
using namespace std;

#define TURE 1


#define FALSE 0
#define ERROR 0
#define OK 1
#define INFEASIBLE -1
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef struct
{
char * elem;
int length;
int listsize;
}SqList;
int Initlist_Sq(SqList &L)
{
L.elem=(char *)malloc(LIST_INIT_SIZE*sizeof(char));
if(!L.elem)
exit(INFEASIBLE);
L.length =0;
L.listsize=LIST_INIT_SIZE;
return OK;

}
int main(void)

{

SqList L1;
Initlist_Sq(L1);
return 0;

}


为什么这么喜欢宏定义?

读书人网 >C++

热点推荐