vc++相关程序问题以及其结构体与简单链表实践相关问题……谢谢了……
4条回答
- 技术专家团-小桥流水 2022-06-23 15:37关注
代码及运行结果如下:
#include <iostream> #include <cstring> using namespace std; struct node { int num;//学号 double CPP;//成绩 node* next; //指向下一个节点的变量指针 }; node* creat() { int n, i; node* head = 0, * p, * t=0; cout << "请输入链表的长度:"; cin >> n; for (i = 0; i < n; i++) { p = new node; cout << "请输入第" << i + 1 << "个学生的学号:"; cin >> p->num; cout << "请输入第" << i + 1 << "个学生的成绩:"; cin >> p->CPP; p->next = 0; if (head == 0) { head = p; t = head; } else { t->next = p; t = p; } } cout << "链表创建完成!" << endl; return head; } void print(node* head) { node* p = head; cout << "显示链表数据:" << endl; while (p) { cout << "学号:" << p->num << "\t成绩:" << p->CPP << endl; p = p->next; } } void release(node* head) { node* p; cout << "释放链表" << endl; while (head) { p = head->next; delete head; head = p; } head = 0; } int main() { node* head = creat(); print(head); release(head); return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
- ¥15 模糊pid与pid仿真结果几乎一样
- ¥15 java的GUI的运用
- ¥15 Web.config连不上数据库
- ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
- ¥15 怎么配置广告联盟瀑布流
- ¥15 Rstudio 保存代码闪退
- ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
- ¥50 invest生境质量模块
- ¥15 nhanes加权logistic回归,svyglm函数