当前位置:   article > 正文

数据结构课作业代码_typedef struct sqlist[maxitem]int f(sqlist r, int

typedef struct sqlist[maxitem]int f(sqlist r, int k,int n) int i=0:while(i

这个代码对于刚学习数据结构的我来说非常的艰难,我是跟着老师的讲解一步步写的

期间出了非常多的错误,像是什么大括号,中英文符号等等

不过最终还是完成了,打卡记录

#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;
}
 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/829274
推荐阅读
相关标签