2021-04-06

最近在学数据结构与算法里面的顺序表
就是简单的插入新的学生信息
#include
#include<stdlib.h>
#include<stdio.h>
using namespace std;
#define Size 10
typedef struct stu
{
int xuehao;
char jiankan[20];
char sex[8];
}stu;
typedef struct biao {
stu* head;
int length;
int size;
}biao;
biao initbiao() {
biao *t= new biao;
t->length = 0;
t->size = Size;
return *t;
}
biao addbiao(biao t, stu elem, int add)
{
int i;
if (add > t.length + 1 || add < 1) {
cout<<“插入位置有问题”;
return t;
}
if (t.length >= t.size) {
;
if (!t.head) {
cout<<“存储分配失败”;
}
t.size += 1;
}
for (i = t.length - 1; i >= add - 1; i–) {
t.head[i]= t.head[i-1];
}
t.head[add - 1]= elem;
t.length++;
return t;
}
void output(stu *head) {
cout << “学生健康情况:” << endl;
cout << head->jiankan;
cout << “学生学号:” << endl;
cout <xuehao;
cout << “学生性别:” << endl;
cout <sex;
}
void displaybiao(biao t) {
int i;
for (i = 0; i < sizeof(t); i++) {
output(&t.head[i]);
}
cout<<“n”;
}
最后运行时
void shuru(biao l,int i) {
cout << “输入学生的健康情况” << endl;
cin>>l.head[i].jiankan;
cout << “输入学生的性别”<<endl;
cin >> l.head[i].sex;
cout << “输入学生的学号” << endl;
cin>>l.head[i].xuehao;

}
stu shuru2(stu& e) {
cin>>e.jiankan;
cin>>e.sex;
cin>>e.xuehao;
return e;
}
int main() {
int num = 0;
int cha = 0;
stu e;
biao a;
a = initbiao();
cout << “输入总人数” << endl;
cin >> num;
for (int i = 0; i < num; i++) {
shuru(a,i);
}
displaybiao(a);
cout<<“输入要加入的学生的健康、性别、学号:”;
shuru2(e);
cout<<“输入要插入的位置:”;
cin>>cha;
a = addbiao(a, e, cha);
displaybiao(a);
return 0;
}
最后运行时候 弹出 istream的文件 说访问权限问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值