当前位置:网站首页>C student management system Insert the student node at the specified location
C student management system Insert the student node at the specified location
2022-08-05 02:19:00 【joker_0030】
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
//学生节点.
typedef struct _STU
{
char arrStuNum[10];
char arrStuName[10];
int iStuScore;
struct _STU* pNext;//指向下一个节点.
}STUNODE;
//申明链表的头和尾.
STUNODE* g_pHead = NULL;
STUNODE* g_pEnd = NULL;
//指定位置添加学生信息.
void InSertNod(STUNODE* pTemp, char* arrStuNum[10], char arrStuName[10], int iStuScore);
int main()
{
int nOrder = -1;
char arrStuNum[10] = { '\0' };
char arrStuName[10] = { '\0' };
int iStuScore = -1;
int nFlag = 1;
STUNODE* pTemp = NULL;
//显示指令.
ShowOrder();
while (nFlag)
{
printf("请输入操作指令(0为查看指令)\n");
scanf("%d", &nOrder);
switch (nOrder)
{
case 1://添加一个学生信息.
printf("输入学号:");
scanf("%s", arrStuNum);
printf("输入姓名:");
scanf("%s", arrStuName);
printf("输入分数:");
scanf("%d", &iStuScore);//取地址.
AddStuMSG(arrStuNum, arrStuName, iStuScore);
break;
case 10://头添加.
printf("输入学号:");
scanf("%s", arrStuNum);
printf("输入姓名:");
scanf("%s", arrStuName);
printf("输入分数:");
scanf("%d", &iStuScore);//取地址.
AddStuMSGToLinkHead(arrStuNum, arrStuName, iStuScore);
break;
case 11://指定位置添加.
printf("输入需要查找的学号:");
scanf("%s", arrStuNum);
pTemp = FindStuByNum(arrStuNum);
if (NULL != pTemp);
{
//插入.
printf("输入学号:");
scanf("%s", arrStuNum);
printf("输入姓名:");
scanf("%s", arrStuName);
printf("输入分数:");
scanf("%d", &iStuScore);
InSertNod(pTemp, arrStuNum, arrStuName, iStuScore);
}
break;
case 2:
printf("请输入学生学号/姓名");
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8://打印数据(链表).
ShowStuData();
break;
case 9:
nFlag = 0;
break;
case 0:
//查看指令.
ShowOrder();
break;
default:
printf("输入的指令不对");
break;
}
}
//释放链表.
FreeLinkData();
system("pause");
return 0;
}
//指定位置添加学生信息.
void InSertNod(STUNODE* pTemp, char* arrStuNum[10], char arrStuName[10], int iStuScore)
{
//创建节点.
STUNODE* pNewTemp = malloc(sizeof(STUNODE));
//成员赋值.
strcpy(pNewTemp->arrStuNum, arrStuNum);//因为数组做参数传入时则完全是一个指针.
strcpy(pNewTemp->arrStuName, arrStuName);//因为数组做参数传入时则完全是一个指针.
pNewTemp->iStuScore = iStuScore;
pNewTemp->pNext = NULL;
if (pTemp == g_pEnd)//是尾节点.
{
g_pEnd->pNext = pNewTemp;//End node next pointpNewTmep.
g_pEnd = pNewTemp;//End node intopNewTmep.
}
else//中间节点.
{
pNewTemp->pNext = pTemp->pNext;
pTemp->pNext = pNewTemp;
}
}
边栏推荐
猜你喜欢
LeetCode uses the minimum cost to climb the stairs----dp problem
Live preview | 30 minutes started quickly!Look at credible distributed AI chain oar architectural design
Transfer Learning - Distant Domain Transfer Learning
Pisanix v0.2.0 released | Added support for dynamic read-write separation
【MySQL系列】- LIKE查询 以%开头一定会让索引失效吗
基于OpenVINO工具套件简单实现YOLOv7预训练模型的部署
Understand the recommendation system in one article: Recall 06: Two-tower model - model structure, training method, the recall model is a late fusion feature, and the sorting model is an early fusion
[LeetCode Brush Questions] - Sum of Numbers topic (more topics to be added)
学习笔记-----左偏树
select 标签自定义样式
随机推荐
PHP技能评测
LeetCode uses the minimum cost to climb the stairs----dp problem
Jincang database KingbaseES V8 GIS data migration solution (3. Data migration based on ArcGIS platform to KES)
[Word] #() error occurs after Word formula is exported to PDF
matlab绘制用颜色表示模值大小的箭头图
Residential water problems
select 标签自定义样式
RAID磁盘阵列
Introduction to SDC
HOG特征学习笔记
基于OpenVINO工具套件简单实现YOLOv7预训练模型的部署
Amazon Cloud Technology joins hands with Thundersoft to build an AIoT platform for industry customers
How to deal with your own shame
Pisanix v0.2.0 发布|新增动态读写分离支持
iNFTnews | 对体育行业和球迷来说,NFT可以带来什么?
进程在用户态和内核态的区别[独家解析]
[parameters of PyQT5 binding functions]
RAID disk array
回顾51单片机
ARM Mailbox