当前位置:网站首页>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;
}
}
边栏推荐
- 学习笔记-----左偏树
- ARM Mailbox
- Residential water problems
- SDC简介
- C语言日记 9 if的3种语句
- 高数_复习_第1章:函数、极限、连续
- [Endnote] Word inserts a custom form of Endnote document format
- 【LeetCode刷题】-数之和专题(待补充更多题目)
- Transfer Learning - Joint Geometrical and Statistical Alignment for Visual Domain Adaptation
- [parameters of PyQT5 binding functions]
猜你喜欢
C语言日记 9 if的3种语句
Optimizing the feed flow encountered obstacles, who helped Baidu break the "memory wall"?
LPQ(局部相位量化)学习笔记
树表的查找
[Endnote] Word inserts a custom form of Endnote document format
释放技术创新引擎,英特尔携手生态合作伙伴推动智慧零售蓬勃发展
Unleashing the engine of technological innovation, Intel joins hands with ecological partners to promote the vigorous development of smart retail
英特尔 XDC 2022 精彩回顾:共建开放生态,释放“基建”潜能
Utilities 树形查找(二叉查找树)
随机推荐
C语言日记 9 if的3种语句
释放技术创新引擎,英特尔携手生态合作伙伴推动智慧零售蓬勃发展
Jincang database KingbaseES V8 GIS data migration solution (3. Data migration based on ArcGIS platform to KES)
Leetcode brushing questions - 22. Bracket generation
领域驱动设计——MDD
特殊矩阵的压缩存储
意识形态的机制
树表的查找
继承关系下构造方法的访问特点
高数_复习_第1章:函数、极限、连续
"Dilili, wait for the lights, wait for the lights", the prompt sound for safe production in the factory
Residential water problems
Matlab map with color representation module value size arrow
“嘀哩哩,等灯等灯”,工厂安全生产的提示音
迁移学习——Distant Domain Transfer Learning
如何逐步执行数据风险评估
Transfer Learning - Distant Domain Transfer Learning
《.NET物联网从零开始》系列
【日常训练】1403. 非递增顺序的最小子序列
Fragment visibility judgment