Visual Sdutio C++中运用单链表完成学生信息管理系统

本文档展示了如何在Visual Studio C++中利用单链表来创建一个学生信息管理系统。系统包括添加、删除、查找和排序学生信息等功能,并提供了详细的操作代码实现。
摘要由CSDN通过智能技术生成

#include<iostream>

using namespace std;

//创建学生结构变量

struct Student

{

long long Id;

char Name[20];

int chineseScore;

int mathScore;

int englishScore;

};

//结点结构体

struct Node

{

Student data;

struct Node* next;

};

//创建头结点

struct Node* create_headNode()

{

struct Node* headNode = (struct Node*)malloc(sizeof(struct Node));

headNode->next = NULL;

return headNode;

}

//创建新结点

struct Node* create_newNode(struct Student data)

{

struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));

newNode->data = data;

newNode->next = NULL;

return newNode;

}

//结点个数

int sizeNode(struct Node* list)

{

struct Node* posNode = list->next;

int size = 0;

while (1)

{

if (posNode == NULL)

{

break;

}

size++;

posNode = posNode->next;

}

return size;

}

//在链表头部增加结点

void InsertNewNodeByHead(struct Node* headNode, Student data)

{

struct Node* newNode = create_newNode(data);

newNode->next = headNode->next;

headNode->next = newNode;

}

//打印

void printNode(struct Node* headNode)

{

if (headNode->next == NULL)

{

cout << "无法打印,链表为空" << endl;

return;

}

else

{

struct Node* pMove = headNode->next;

while (pMove)

{

cout << "学号:" << pMove->data.Id << "\t" << "姓名:" << pMove->data.Name << "\t" << "语文成绩:" << pMove->data.chineseScore << "\t" << "数学成绩:" << pMove->data.mathScore << "\t"

<< "英语成绩:" << pMove->data.englishScore << endl;

pMove = pMove->next;

}

return;

}

}

//清空链表

void freeNode(struct Node* headNode)

{

//struct Node* posNode = headNode->next;//目标结点

//while (posNode != NULL)

//{

// struct Node* posNext = posNode->next;

// free(posNode);

// posNode = posNext;

//}

//free(headNode);

if (headNode->next == NULL)

{

cout << "链表已为空" << endl;

return;

}

while (headNode->next)

{

struct Node* posNode = headNode;

struct Node* posNext = posNode->next;

posNode->next = posNext->next;

free(posNext);

}

cout << "已经清空链表" << endl;

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

boss_in_boss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值