温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

C语言中怎么利用链表实现一个学生信息管理系统

发布时间:2021-08-07 11:42:41 来源:亿速云 阅读:114 作者:Leah 栏目:编程语言

本篇文章为大家展示了C语言中怎么利用链表实现一个学生信息管理系统,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

代码实现的功能:

1.插入学生信息 2.显示学生信息 3.删除学生信息 4.在指定位置插入学生信息 5.查找学生信息

代码内容:

#include <stdio.h>#include <stdlib.h>#include <string.h>#define Max_Student_Num 10#define Max_Str_len 20typedef struct T_student{ int number; char name [Max_Student_Num]; char phone[Max_Student_Num];};typedef struct T_Node{ struct T_student s; struct T_Node * next;};char command_str[]={"\n1 display all member;\n2 insert member;\n3 del member;\n4 exit\nCommand selection:"};struct T_student students[Max_Student_Num];struct T_Node * head = NULL;int main(int argc, char* argv[]){ int command, i; struct T_student student; struct T_Node * pStu =head; memset(&student,0,sizeof(student)); while(1){  printf("%s",command_str);  scanf("%d", &command);  switch(command)  {  case 1:   if(head==NULL){    printf("empty!!!!!!!!!!!!\n");    break;   }   if(head->next==head){    display_student(head);   }else{    pStu=head->next;    do    {     display_student(pStu);     pStu=pStu->next;    }while(pStu!= head->next);//   }   break;  case 2:   printf("enter new student number:");   scanf("%d", &student.number);   printf("enter new student name:");   scanf("%s", &student.name);   if(strlen(student.name) > Max_Str_len)   {    printf("name is too long!!\n");    continue;   }   printf("enter new student phone:");   scanf("%s", &student.phone);   if(strlen(student.phone) > Max_Str_len)   {    printf("phone is too long!!\n");    continue;   }   printf("\n");   if(student.number != 0)     insert_student(student);   break;  case 3:   printf("Inter deleted student number:");   scanf("%d", &student.number);   del_student(student);   break;  case 4:   return 0;  default:   printf("error command, try again\n");   break;  } }}void display_student( struct T_Node * pStu){ printf("number:%d name:%s phone:%s \n",pStu->s.number,pStu->s.name,pStu->s.phone);}void insert_student(struct T_student student){ struct T_Node* pNode ; struct T_Node* pStu =NULL; int size = sizeof(struct T_Node); pStu=(struct T_Node *)malloc (size); if(pStu == NULL){  return ; } memcpy(&pStu->s,&student,sizeof(student)); if(head==NULL){   pStu->next=head;   head=pStu;   head->next=head;   return ; } pStu->next = head->next; head->next=pStu;}void del_student(struct T_student student){ struct T_Node *pNode =NULL,*p=NULL; if(head->next==head && head->s.number==student.number){  pNode=head;  head=NULL;  free(pNode);  printf("success");  return; } for(pNode=head->next;pNode != head;pNode=pNode->next){  if( pNode->next->s.number == student.number){   p=pNode->next->next;   free(pNode->next);   pNode->next=p;   printf("Delete success!\n");   return;  } } printf("Not Found\n");}

上述内容就是C语言中怎么利用链表实现一个学生信息管理系统,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI