线性表的定义

wmxfdfj 2008-10-20 10:54:16
我写了个程序,但就是调不出来,麻烦各位帮我看一下谢谢!
#include <iostream>
#include <stdlib.h>

const int Ms = 20;
//定义常量为20

struct Student{
int num;
//学号
double grade;
//成绩
};

typedef Student ElemType;
//定义ElemType为Student类型

struct ListSq{
ElemType *list;
//存线性表元素
int len;
//存线性表长度
int MaxSize;
//存List数长度,即所能存储的长度
};

void InitList(ListSq& L);
//初始置空线性表,即置各域值为0
void InitList(ListSq& L,int ms);
//分配MS大小的线性表空间
ElemType GetElemList(ListSq& L,int pos);
//得到线性表好、中第pos个元素的值
int SeqFindList(ListSq L,ElemType item);
//从线性表顺序查找一个元素,返回该元素位置
int BinFindList(ListSq& L,ElemType item);
//从线性表中二分查找一个元素,返回该元素位置
bool ModifyList(ListSq& l,const ElemType item);
//修改线性表中第一个指定元素
void TailInsertList(ListSq& L,ElemType item);
//向线性表尾部插入一个元素
void OrderInserList(ListSq& L,ElemType item);
//向线性表有序位置插入一个元素
bool DeleteList(ListSq& L,ElemType item);
//从线性表中删除第一元素
bool EmptyList(ListSq& L);
//判断线性表是否为空
int LenthList(ListSq& L);
//求线性表长度
void OutputList(ListSq& L);
//遍历输出线性表
void SortListl(ListSq& L);
//按元素的值或关键字对顺序存储的线性表就地排序
ListSq SortList2(const ListSq& L);
//清除线性表中的所有元素,释放线性表中动态存储空间
void ClearList(ListSq& L);

static bool operator == (const ElemType& s1,const ElemType& s2)
{
return s1.num == s2.num;
}

static bool operator < (const ElemType& s1,const ElemType& s2)
{
return s1.num < s2.num;
}
static ostream& operator << (ostream& ostr,const ElemType& s)
{
ostr << s.num << ' ' s.grade << ' ';
return ostr;
}
错误提示:xb1.cpp
E:\编程\xxb1.cpp(65) : error C2143: syntax error : missing ';' before '&'
E:\编程\xxb1.cpp(65) : error C2061: syntax error : identifier 'ostream'
E:\编程\xxb1.cpp(66) : error C2501: '<<' : missing storage-class or type specifiers
E:\编程\xxb1.cpp(66) : error C2809: 'operator <<' has no formal parameters
E:\编程\xxb1.cpp(67) : error C2065: 'ostr' : undeclared identifier
E:\编程\xxb1.cpp(67) : error C2065: 's' : undeclared identifier
E:\编程\xxb1.cpp(67) : error C2228: left of '.num' must have class/struct/union type
E:\编程\xxb1.cpp(67) : error C2146: syntax error : missing ';' before identifier 's'
E:\编程\xxb1.cpp(67) : error C2228: left of '.grade' must have class/struct/union type
Error executing cl.exe.

xxb1.obj - 9 error(s), 0 warning(s)
...全文
326 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
elegant87 2008-10-21
  • 打赏
  • 举报
回复

//LZ 注意了C++头文件的定义规则哦!
//1.用#include <iostream>时候学要加上using namespace std;命名空间的!
//2.或者用C语言头文件的形式,#include <iostream.h>,#include <stdlib.h>
#include <iostream>
#include <cstdlib>

using namespace std;//问题在这哦

const int Ms = 20;
//定义常量为20

struct Student{
int num;
//学号
double grade;
//成绩
};

typedef Student ElemType;
//定义ElemType为Student类型

struct ListSq{
ElemType *list;
//存线性表元素
int len;
//存线性表长度
int MaxSize;
//存List数长度,即所能存储的长度
};

void InitList(ListSq& L);
//初始置空线性表,即置各域值为0
void InitList(ListSq& L,int ms);
//分配MS大小的线性表空间
ElemType GetElemList(ListSq& L,int pos);
//得到线性表好、中第pos个元素的值
int SeqFindList(ListSq L,ElemType item);
//从线性表顺序查找一个元素,返回该元素位置
int BinFindList(ListSq& L,ElemType item);
//从线性表中二分查找一个元素,返回该元素位置
bool ModifyList(ListSq& l,const ElemType item);
//修改线性表中第一个指定元素
void TailInsertList(ListSq& L,ElemType item);
//向线性表尾部插入一个元素
void OrderInserList(ListSq& L,ElemType item);
//向线性表有序位置插入一个元素
bool DeleteList(ListSq& L,ElemType item);
//从线性表中删除第一元素
bool EmptyList(ListSq& L);
//判断线性表是否为空
int LenthList(ListSq& L);
//求线性表长度
void OutputList(ListSq& L);
//遍历输出线性表
void SortListl(ListSq& L);
//按元素的值或关键字对顺序存储的线性表就地排序
ListSq SortList2(const ListSq& L);
//清除线性表中的所有元素,释放线性表中动态存储空间
void ClearList(ListSq& L);

static bool operator == (const ElemType& s1,const ElemType& s2)
{
return s1.num == s2.num;
}

static bool operator < (const ElemType& s1,const ElemType& s2)
{
return s1.num < s2.num;
}
static ostream& operator<<(ostream& ostr,const ElemType& s)
{
ostr<<s.num<<' '<< s.grade<<' ';
return ostr;
}

int main()
{
cout<<"Successful!"<<endl;
return 0;
}
wmxfdfj 2008-10-21
  • 打赏
  • 举报
回复
呵呵,谢谢各位的热心,我刚自学c++,我以前学过C,以后还箐多多关照。
wmxfdfj 2008-10-20
  • 打赏
  • 举报
回复
谢谢
chlaws 2008-10-20
  • 打赏
  • 举报
回复

#include <iostream>
using namespace std;
#include <iostream>
#include <stdlib.h>

const int Ms = 20;
//定义常量为20

struct Student{
int num;
//学号
double grade;
//成绩
};

typedef Student ElemType;
//定义ElemType为Student类型

struct ListSq{
ElemType *list;
//存线性表元素
int len;
//存线性表长度
int MaxSize;
//存List数长度,即所能存储的长度
};

void InitList(ListSq& L);
//初始置空线性表,即置各域值为0
void InitList(ListSq& L,int ms);
//分配MS大小的线性表空间
ElemType GetElemList(ListSq& L,int pos);
//得到线性表好、中第pos个元素的值
int SeqFindList(ListSq L,ElemType item);
//从线性表顺序查找一个元素,返回该元素位置
int BinFindList(ListSq& L,ElemType item);
//从线性表中二分查找一个元素,返回该元素位置
bool ModifyList(ListSq& l,const ElemType item);
//修改线性表中第一个指定元素
void TailInsertList(ListSq& L,ElemType item);
//向线性表尾部插入一个元素
void OrderInserList(ListSq& L,ElemType item);
//向线性表有序位置插入一个元素
bool DeleteList(ListSq& L,ElemType item);
//从线性表中删除第一元素
bool EmptyList(ListSq& L);
//判断线性表是否为空
int LenthList(ListSq& L);
//求线性表长度
void OutputList(ListSq& L);
//遍历输出线性表
void SortListl(ListSq& L);
//按元素的值或关键字对顺序存储的线性表就地排序
ListSq SortList2(const ListSq& L);
//清除线性表中的所有元素,释放线性表中动态存储空间
void ClearList(ListSq& L);

static bool operator == (const ElemType& s1,const ElemType& s2)
{
return s1.num == s2.num;
}

static bool operator < (const ElemType& s1,const ElemType& s2)
{
return s1.num < s2.num;
}
static ostream& operator << (ostream& ostr,const ElemType& s)
{
ostr << s.num << ' ' <<s.grade << ' ';
return ostr;
}

int main()
{
cout << "test"<<endl;
return 0;
}

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧