服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - C/C++ - C语言使用链表实现学生信息管理系统

C语言使用链表实现学生信息管理系统

2021-08-11 14:40Newtol C/C++

这篇文章主要为大家详细介绍了C语言使用链表实现学生信息管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了C语言实现学生信息管理系统的具体代码,供大家参考,具体内容如下

代码实现的功能:

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

代码内容:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define Max_Student_Num 10
#define Max_Str_len 20
 
typedef 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");
}

测试截图:

1.插入功能: 
C语言使用链表实现学生信息管理系统
2.显示功能: 
C语言使用链表实现学生信息管理系统
3.查询功能: 
C语言使用链表实现学生信息管理系统
4.删除功能: 
C语言使用链表实现学生信息管理系统
5.指定位置插入: 
C语言使用链表实现学生信息管理系统

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://www.cnblogs.com/newtol/p/10159127.html

延伸 · 阅读

精彩推荐