赞
踩
这个代码对于刚学习数据结构的我来说非常的艰难,我是跟着老师的讲解一步步写的
期间出了非常多的错误,像是什么大括号,中英文符号等等
不过最终还是完成了,打卡记录
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
#define OK 1 //表示函数功能执行成功
#define ERROR 0 //表示函数功能执行失败
#define OVERFLOW -1
#define ElemType string //表示函数执行时溢出
#define MAXSIZE 4
#define Status int
typedef struct SqList
{
ElemType* e;
int length;
}SqList;
int main()
{
Status InitList(SqList &L);
Status CreateList(SqList &L);
SqList L;
InitList(L);
CreateList(L);
return 0;
}
//基本操作1:初始化(构造一个空的线性表)
Status InitList(SqList &L)
{
L. e = new ElemType[MAXSIZE];
if (!L. e)
return ERROR;
L. length = 0;
return OK;
}
//基本操作2:创建(把学生名单输入此线性表)
Status CreateList(SqList &L)
{
string student_name;
cout << "请通过键盘输入学生姓名(以空格为间隔,回车结束,0退出):";
cin >> student_name;
int i = 0;
while (student_name != "0")
{
if (L. length == MAXSIZE)
{
cout << "\n\n出错,超出课程教室容量";
return ERROR;
}
L. e[i++] = student_name;
L. length++;
if (cin.get() == '\n')
cout << "请继续键盘输入学生的姓名:";
cin >> student_name;
}
cout << "创建学生选课名单成功!\n选课学生共:"<< i <<"名:\n\n";
for (i = 0; i < L. length; i++)
cout << L. e[ i ] << "\n";
return OK;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。