python列表输出学生姓名学号链表_c语言!!!程序设计:建立一个学生信息链表,包括学号,姓名,成绩.(实现添加,删除,查询,排序,平均)...

展开全部

代码如下:

/*用c语言链表编写一个学生信息系统程序,62616964757a686964616fe4b893e5b19e31333365656636要求输出学生的学号,姓名,性别,

学号,姓名,成绩.(实现添加,删除,查询,排序,平均)*/

#include

#include

#include

#include

using namespace std;

const int n=5;

/*

* nodeEntry : 节点数据类型

* nodeADT   : 节点结构

* linkADT   : 链表结构

*/

typedef struct Student

{

int num;

char name[30];

char sex;

float score1;//语文

float score2;//数学

float score3;//英语

//struct Student *next;

}Student;

typedef struct nodeCDT {

Student entry;

struct nodeCDT *next;

}*nodeADT;

typedef struct linkCDT {

nodeADT head;

}*linkADT;

/*

* InitLink   : 初始化链表

* CreateNode : 创建节点

* AppendLink : 添加数据

*/

void InitLink(linkADT *link) {

*link=(linkADT)malloc(sizeof*(*link));

(*link)->head=0;

}

nodeADT CreateNode(Student entry) {

nodeADT p=(nodeADT)malloc(sizeof*p);

p->entry=entry,p->next=0;

return p;

}

void AppendLink(linkADT *link,Student entry) {

nodeADT newNode=CreateNode(entry),p;

if (!*link) InitLink(link);

if (!(*link)->head) (*link)->head=newNode;

else {

for (p=

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C语言中,我们可以使用结构体(struct)和链表数据结构来创建一个存储学生信息学生链表。这里是一个简单的例子,首先定义一个`Student`结构体,然后创建一个链表节点,并实现链表的基本操作,如添加新节点、遍历等。 ```c // 定义学生结构体 typedef struct { int student_id; // 学号 char name[50]; // 姓名 float score; // 成绩 } Student; // 链表节点定义 typedef struct Node { Student info; struct Node* next; } Node; // 初始化链表头指针 Node* head = NULL; // 添加新节点到链表 void addStudent(Student new_student) { Node* newNode = (Node*)malloc(sizeof(Node)); newNode->info = new_student; newNode->next = head; head = newNode; } // 添加新节点的辅助函数(已知学号插入) void insertAtStudentId(int id, Student new_student) { Node* current = head; while (current && current->info.student_id != id) { current = current->next; } if (current) { newNode = (Node*)malloc(sizeof(Node)); newNode->info = new_student; newNode->next = current->next; current->next = newNode; } else { printf("Student with ID %d not found.\n", id); } } // 遍历链表并打印学生信息 void printStudentList() { Node* temp = head; while (temp) { printf("ID: %d, Name: %s, Score: %.2f\n", temp->info.student_id, temp->info.name, temp->info.score); temp = temp->next; } } // 示例:创建并添加学生 int main() { Student new_student = {1001, "Alice", 90.5}; addStudent(new_student); // 插入新学生到特定学号位置 insertAtStudentId(1002, {1002, "Bob", 85.0}); // 打印链表中的所有学生信息 printStudentList(); return 0; }

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值