#include <string>
#include <iostream>
#include <stdio.h>
using namespace std;
typedef struct _student
{
string sid;
string name;
string sex;
string cls;
string major;
}student;
typedef struct _NODE
{
student stu;
_NODE *next;
}NODE, *PNODE;
PNODE add(PNODE head)
{
PNODE pNode = new NODE;
pNode->next = NULL;
cout << "请输入学生学号:";
cin >> pNode->stu.sid;
cout << "请输入学生姓名:";
cin >> pNode->stu.name;
cout << "请输入学生性别:";
cin >> pNode->stu.sex;
cout << "请输入学生班级:";
cin >> pNode->stu.cls;
cout << "请输入学生专业:";
cin >> pNode->stu.major;
if (head == NULL)
{
head = pNode;
return head;
}
else
{
pNode->next = head;
head = pNode;
}
return head;
}
void show(PNODE head)
{
if (head == NULL)
return;
cout << "学号\t" << "姓名\t" << "性别\t" << "班级\t" << "专业" << endl;
while (head != NULL)
{
cout << head->stu.sid << "\t" << head->stu.name << "\t" << head->stu.sex << "\t" << head->stu.cls << "\t" << head->stu.major << endl;
head = head->next;
}
}
void main()
{
PNODE head = NULL;
int n;
cout << "请输入学生数量:";
cin >> n;
for (int i = 0; i < n; i++)
head = add(head);
show(head);
}
你这个并不难啊,学生信息定义成一个结构,再加一个结构的next指针就可以建立链表了
你这是C++还是C啊
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632