关于switchcase语句中break后会不会释放缓存?
程序代码:
// 学生管理系统.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "stdio.h" #include "stdlib.h" #include "string.h" #define LEN 1024 //================================== void vIface(); void vgn2(); //学生成员结构 typedef struct sStudent { int iNumber; char cName[50]; char cSex[4]; int iAge; int iGrade; int iClass; int iSeat; float fChina; float fEnglish; float fMath; double dAverage; double dTotal; sStudent* pNext; }cstu[LEN],stu; //创建单链表并录入数据 stu* screate(stu* lhead) { int i=0; char Yn[4]; stu* pNew, *pEnd; lhead =(stu*) malloc(sizeof(stu)); if (lhead == NULL) { printf("创建头节点失败!\n"); exit(1); } pEnd = lhead; printf("输入y或者n选择操作:\n"); scanf_s("%s", Yn,4); while(strncmp(Yn,"Y",4)==0|| strncmp(Yn, "y", 4) == 0) { i++; pNew= (stu*)malloc(sizeof(stu)); printf("学号:"); scanf_s("%d", &pNew->iNumber); printf("姓名:"); scanf_s("%s", pNew->cName,50); printf("性别:"); scanf_s("%s", pNew->cSex,4); printf("年龄:"); scanf_s("%d", &pNew->iAge); printf("年级:"); scanf_s("%d", &pNew->iGrade); printf("班级:"); scanf_s("%d", &pNew->iClass); printf("座位:"); scanf_s("%d", &pNew->iSeat); printf("请输入三门科目成绩:\n"); getchar(); printf("语文:"); scanf_s("%f", &pNew->fChina); printf("数学:"); scanf_s("%f", &pNew->fMath); printf("英语:"); scanf_s("%f", &pNew->fEnglish); if (pNew == NULL) { pEnd = pNew; } else { pNew->pNext = NULL; pEnd->pNext = pNew; pEnd = pNew; } getchar(); printf("输入y或者n选择操作:\n"); scanf_s("%c", Yn, 4); if (strncmp(Yn, "Y", 4) != 0 || strncmp(Yn, "y", 4) != 0) { continue; } } pEnd->pNext = NULL; return lhead; } //打印学生管理系统链表 void vPrint(stu* lHead) { int i=0; stu* sTemp; sTemp = lHead; if (sTemp == NULL) { printf("空链表!\n"); exit(1); } sTemp=sTemp->pNext; while (sTemp!= NULL) { sTemp->dTotal = sTemp->fChina + sTemp->fMath + sTemp->fEnglish; sTemp->dAverage = sTemp->dTotal / 3; printf("学号\t姓名\t性别\t年龄\t年级\t班级\t座位\t 语文\t\t 数学\t\t 英语\t\t 总分数\t 平均分\n"); printf("%d\t %s\t %s\t %d\t %d\t %d\t %d\t %.4f分\t %.4f\t %.4f\t %.4lf\t %.4lf\n", sTemp->iNumber, sTemp->cName, sTemp->cSex, sTemp->iAge, sTemp->iGrade, sTemp->iClass, sTemp->iSeat, sTemp->fChina, sTemp->fMath, sTemp->fEnglish, sTemp->dTotal, sTemp->dAverage); sTemp = sTemp->pNext; ++i; } printf("总节点为:%d\n", i); } void vSearch(stu* lHead,int search_num) { int i = 0; stu* iTemp; iTemp = lHead; if (iTemp == NULL) { printf("空链表"); exit(1); } iTemp = iTemp->pNext; while (iTemp!=NULL) { i++; iTemp = iTemp->pNext; iTemp->dTotal = iTemp->fChina + iTemp->fMath + iTemp->fEnglish; iTemp->dAverage = iTemp->dTotal / 3; if (iTemp->iNumber == search_num) { printf("查询到以下信息:\n"); printf("\n"); printf("学号\t姓名\t性别\t年龄\t年级\t班级\t座位\t 语文\t\t 数学\t\t 英语\t\t 总分数\t 平均分\n"); printf("%d\t %s\t %s\t %d\t %d\t %d\t %d\t %.4f分\t %.4f\t %.4f\t %.4lf\t %.4lf\n", iTemp->iNumber, iTemp->cName, iTemp->cSex, iTemp->iAge, iTemp->iGrade, iTemp->iClass, iTemp->iSeat, iTemp->fChina, iTemp->fMath, iTemp->fEnglish, iTemp->dTotal, iTemp->dAverage); break; } } printf("\n"); printf("查询成功!\n"); } void vIface() { printf("\t=============================学生信息管理系统=============================\n"); printf("\t*\t\t\t\t\t\t\t\t"); printf("\t *\n"); printf("\t*\t\t\t\t\t\t\t\t"); printf("\t *\n"); printf("\t*\t\t\t"); printf(" *1.录入学生信息*"); printf("\t\t\t\t *\n"); printf("\t*\t\t\t\t\t\t\t\t"); printf("\t *\n"); printf("\t*\t\t\t"); printf(" *2.查询学生信息*"); printf("\t\t\t\t *\n"); printf("\t*\t\t\t\t\t\t\t\t"); printf("\t *\n"); printf("\t*\t\t\t"); printf(" *3.打印学生信息*"); printf("\t\t\t\t *\n"); printf("\t*\t\t\t\t\t\t\t\t"); printf("\t *\n"); printf("\t*\t\t\t"); printf(" *4.删除学生信息*"); printf("\t\t\t\t *\n"); printf("\t*\t\t\t\t\t\t\t\t"); printf("\t *\n"); printf("\t*\t\t\t"); printf(" *5.排序学生成绩*"); printf("\t\t\t\t *\n"); printf("\t*\t\t\t\t\t\t\t\t"); printf("\t *\n"); printf("\t*\t\t\t"); printf(" *6.保存学生信息*"); printf("\t\t\t\t *\n"); printf("\t*\t\t\t\t\t\t\t\t"); printf("\t *\n"); printf("\t*\t\t\t"); printf(" *7.载入学生信息*"); printf("\t\t\t\t *\n"); printf("\t*\t\t\t\t\t\t\t\t"); printf("\t *\n"); printf("\t*\t\t\t"); printf(" *8.修改学生信息*"); printf("\t\t\t\t *\n"); printf("\t*\t\t\t\t\t\t\t\t"); printf("\t *\n"); printf("\t*\t\t\t"); printf(" *8.退出系统操作*"); printf("\t\t\t\t *\n"); printf("\t*\t\t\t\t\t\t\t\t"); printf("\t *\n"); printf("\t*\t\t\t\t\t\t\t\t"); printf("\t *\n"); printf("\t=============================学生信息管理系统=============================\n"); vgn2(); } //界面选项操作 void vgn2() { stu* itemp=NULL; int inum; int itemp_num; printf("输入1~8并回车选择需要操作的选项:\n"); scanf_s("%d", &inum); switch (inum) { case 1: screate(itemp); break; case 2: printf("输入要查询的节点:\n"); scanf_s("%d", &itemp_num); vSearch(itemp, itemp_num); break; case 3: vPrint(itemp); break; default: printf("操作错误!\n"); break; } vIface(); } int main() { //stu* itemp; //int inum; /*itemp=screate(); vPrint(itemp); printf("输入要查询的节点:\n"); scanf_s("%d", &inum); vSearch(itemp,inum);*/ vIface(); return 0; }
这是一段单链表伪代码,在main函数直接调用时,录入数据后可以打印出来,可以查询数据。
我想实现单链表各功能选择项操作。使用switch语句之后,录入数据之后,再回到界面选择打印之前录入的数据,只有显示空链表,没有数据。
我想问一下各位前辈。是否return 的head节点因为break,所以释放了缓存?