鱼C论坛

 找回密码
 立即注册
查看: 4294|回复: 5

[作品展示] 仿学生管理系统

[复制链接]
发表于 2020-3-7 14:15:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
简单的增删改查,链表的排序还不会,勿喷,代码数最长的一次,
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>

  4. typedef struct _node
  5. {
  6.     char name[64];
  7.     char id[10];
  8.     char score[64];
  9.     struct _node *next;
  10. } Node;

  11. typedef struct _list
  12. {
  13.     Node *head;
  14. } List;

  15. //--1--插入新的学生(头插法)
  16. void AddStudentByHead(List *list);
  17. //尾插法V1
  18. void AddStudentByEndV1(List *list);
  19. //尾插法V2只能单独使用
  20. void AddStudentByEndV2(List *list);
  21. void ChangeStudent(List *list, char *input);
  22. void Input(Node *p);
  23. int Search(List *list, char *input);
  24. void Delete(List *list, char *input);
  25. void PrintStudent(List *list);
  26. void ClearList(List *list);
  27. Node *PrintFlage(List *list, char *input);

  28. int main(void)
  29. {
  30.     List list;
  31.     list.head = NULL;
  32.     char code;
  33.     int c;
  34.     char input1[64];
  35.     char input2[64];
  36.     char input3[64];
  37.     int flag = 0;
  38.     Node *temp;
  39.     while (1)
  40.     {
  41.         printf("欢迎使用学生成绩管理系统\n");
  42.         printf("----1.插入新的学生-----\n");
  43.         printf("----2.查找已有学生----\n");
  44.         printf("----3.更改学生--------\n");
  45.         printf("----4.删除已有学生----\n");
  46.         printf("----5.显示已有学生----\n");
  47.         printf("----6.退出系统-------\n");

  48.         printf("请输入指令代码(1-6)\n");
  49.         do
  50.         {
  51.             scanf("%c", &code);
  52.         } while (code>54||code<49);
  53.         
  54.       

  55.         switch (code)
  56.         {

  57.         case '1':
  58.             printf("请选择插入学生的方法(1-头插法 2-尾插法V1):");
  59.             scanf("%d", &c);

  60.             switch (c)
  61.             {
  62.             case 1:
  63.                 AddStudentByHead(&list);
  64.                 break;
  65.             case 2:
  66.                 AddStudentByEndV1(&list);
  67.                 break;

  68.             default:
  69.                 printf("输入指令错误\n");
  70.             }
  71.             break;

  72.         case '2':
  73.             printf("请输入你要查找的学生:");
  74.             scanf("%s", input1);
  75.             flag = (Search(&list, input1));
  76.             if (flag > 0)
  77.             {
  78.                 temp = PrintFlage(&list, input1);
  79.                 printf("学生姓名:%s\t学号%s\t分数:%s\t", temp->name, temp->id, temp->score);
  80.             }
  81.             else
  82.             {
  83.                 printf("不好意思,查无此人\n");
  84.             }
  85.             break;

  86.         case '3':
  87.             printf("请输入你要更改的学生名字:");
  88.             scanf("%s", input2);
  89.             flag = Search(&list, input2);
  90.             temp = PrintFlage(&list, input2);
  91.             if (flag > 0)
  92.             {
  93.                 printf("当前的学生信息为:\n");
  94.                 printf("学生姓名:%s\t学号%s\t分数:%s\t", temp->name, temp->id, temp->score);
  95.                 printf("请输入您要更改的学生信息\n");
  96.                 ChangeStudent(&list, input2);
  97.             }
  98.             else
  99.             {
  100.                 printf("不好意思,你要更改的学生名字尚未存在\n");
  101.             }
  102.             break;

  103.         case '4':

  104.             printf("请输入你要删除的学生名字:");
  105.             scanf("%s", input3);
  106.             if (Search(&list, input3) > 0)
  107.             {
  108.                 Delete(&list, input3);
  109.             }
  110.             else
  111.             {
  112.                 printf("不好意思,你要删除的学生名字尚未存在\n");
  113.             }
  114.             break;

  115.         case '5':
  116.             PrintStudent(&list);
  117.             break;
  118.         case '6':
  119.             if (!list.head)
  120.             {
  121.                 printf("还没有信息呢\n");
  122.             }
  123.             goto END;

  124.         default:
  125.             printf("输入指令错误\n");
  126.             break;
  127.         }
  128.         printf("^__^\n");
  129.         printf("\n\n");
  130.     }
  131. END:
  132.     ClearList(&list), printf("删库跑路成功^__^\n");

  133.     system("pause");
  134.     return 0;
  135. }
  136. //--1--插入新的学生
  137. void AddStudentByHead(List *list)
  138. {
  139.     Node *p, *temp;
  140.     p = (Node *)malloc(sizeof(Node));
  141.     Input(p);

  142.     if (list->head)
  143.     {
  144.         temp = list->head;
  145.         list->head = p;
  146.         p->next = temp;
  147.     }
  148.     else
  149.     {
  150.         list->head = p;
  151.         p->next = NULL;
  152.     }
  153. }
  154. //尾插法
  155. void AddStudentByEndV1(List *list)
  156. {
  157.     Node *p;
  158.     p = (Node *)malloc(sizeof(Node ));
  159.     Input(p);

  160.     Node *last;
  161.     last = list->head;

  162.     if (last)
  163.     {
  164.         while (last->next)
  165.         {
  166.             last = last->next;
  167.         }
  168.         last->next = p;
  169.         p->next=NULL;
  170.     }
  171.     else
  172.     {
  173.         list->head = p;
  174.         p->next = NULL;
  175.     }
  176. }
  177. //尾插法
  178. /*
  179. void AddStudentByEndV2(List *list)
  180. {
  181.     Node *p;
  182.     p = (Node *)malloc(sizeof(Node ));
  183.     Input(p);
  184.     static Node *tail;

  185.     if (list->head)
  186.     {
  187.         tail=list->head;
  188.         tail->next = p;
  189.         p->next = NULL;
  190.     }
  191.     else
  192.     {
  193.         list->head = p;
  194.         p->next = NULL;
  195.     }

  196.     tail = p;
  197. }
  198. */
  199. void ChangeStudent(List *list, char *input)
  200. {
  201.     Node *p;
  202.     for (p = list->head; p; p = p->next)
  203.     {
  204.         if (!strcmp(p->name, input))
  205.         {
  206.             Input(p);
  207.             break;
  208.         }
  209.     }
  210. }
  211. void Input(Node *p)
  212. {
  213.     printf("请输入姓名:");
  214.     scanf("%s", p->name);
  215.     printf("请输入学号(2位数字):");
  216.     scanf("%s", p->id);
  217.     printf("请输入学生分数(小于1000):");
  218.     scanf("%s", p->score);
  219. }
  220. int Search(List *list, char *input)
  221. {
  222.     int flag = -1; //标志
  223.     Node *p;
  224.     for (p = list->head; p; p = p->next)
  225.     {
  226.         if (!strcmp(p->name, input))
  227.         {
  228.             flag = 1;
  229.             break;
  230.         }
  231.     }

  232.     return flag;
  233. }
  234. Node *PrintFlage(List *list, char *input)
  235. {
  236.     Node *p;
  237.     for (p = list->head; p; p = p->next)
  238.     {
  239.         if (!strcmp(p->name, input))
  240.         {

  241.             break;
  242.         }
  243.     }
  244.     return p;
  245. }
  246. void Delete(List *list, char *input)
  247. {
  248.     Node *p, *q = NULL;
  249.     for (p = list->head; p; q = p, p = p->next)
  250.     {
  251.         if (!strcmp(p->name,input))
  252.         {

  253.             if (q)
  254.             {
  255.                 q->next = p->next;
  256.                
  257.             }
  258.             else
  259.             {
  260.                 list->head = p->next;  
  261.             }
  262.             free(p);
  263.             break;
  264.         }
  265.         
  266.     }
  267. }
  268. void PrintStudent(List *list)
  269. {
  270.     Node *p;
  271.     for (p = list->head; p; p = p->next)
  272.     {
  273.         printf("学生姓名:%s\t学号:%s\t分数:%s\t\n", p->name, p->id, p->score);
  274.     }
  275. }
  276. //--6--删库跑路
  277. void ClearList(List *list)
  278. {
  279.     Node *p, *q;
  280.     for (p = list->head; p; p = q)
  281.     {
  282.         q = p->next;
  283.         free(p);
  284.     }
  285. }
复制代码



小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-3-7 14:32:14 | 显示全部楼层
还是@zltzlt 的功能全
这是Ta的代码(Python)
  1. import pickle
  2. from os.path import isfile
  3. from os import remove


  4. def main():
  5.     running = True
  6.     while running:
  7.         menu()
  8.         code = '9'
  9.         count = 0
  10.         while code not in [str(i) for i in range(8)]:
  11.             if count == 0:
  12.                 code = input("请输入:")
  13.             else:
  14.                 code = input("输入有误!请重新输入:")
  15.             count += 1
  16.         if code == '0':
  17.             running = False
  18.         elif code == '1':
  19.             insert()
  20.         elif code == '2':
  21.             search()
  22.         elif code == '3':
  23.             delete()
  24.         elif code == '4':
  25.             modify()
  26.         elif code == '5':
  27.             sort()
  28.         elif code == '6':
  29.             total()
  30.         elif code == '7':
  31.             show()
  32.     else:
  33.         input("感谢您使用学生信息查询系统程序,请按 <Enter> 键退出程序!")


  34. def menu():
  35.     print('''
  36.     ╔———————————————学生信息管理系统————————————————╗

  37.         =============== 功能菜单 ================

  38.         1 录入学生信息
  39.         2 查找学生信息
  40.         3 删除学生信息
  41.         4 修改学生信息
  42.         5 排序
  43.         6 统计学生总人数
  44.         7 显示所有学生信息
  45.         0 退出系统
  46.        ==========================================
  47.        说明:通过数字选择菜单
  48.     ╚——————————————————————————————————————————————╝
  49.         ''')


  50. def insert():
  51.     continue_ = 'y'
  52.     while continue_ == 'y':
  53.         ID = input("请输入 ID(如 1001):")
  54.         name = input("请输入名字:")
  55.         chinese = input("请输入语文成绩:")
  56.         while not is_float(chinese):
  57.             chinese = input("输入无效!请重新输入语文成绩:")
  58.         chinese = float(chinese)
  59.         math = input("请输入数学成绩:")
  60.         while not is_float(math):
  61.             math = input("输入无效!请重新输入数学成绩:")
  62.         math = float(math)
  63.         english = input("请输入英语成绩:")
  64.         while not is_float(english):
  65.             english = input("输入无效!请重新输入英语成绩:")
  66.         english = float(english)

  67.         score = [{'id': ID, 'name': name,
  68.                   'chinese': chinese, 'math': math, 'english': english}]

  69.         if not isfile("students.pkl"):
  70.             file = open("students.pkl", "ab")
  71.             pickle.dump(score, file)
  72.             file.close()
  73.         else:
  74.             file = open("students.pkl", "rb+")
  75.             score_list = pickle.load(file)
  76.             score_list.extend(score)
  77.             file.close()
  78.             file = open("students.pkl", "wb")
  79.             pickle.dump(score_list, file)
  80.             file.close()

  81.         continue_ = input("是否继续添加?(y/n)")
  82.         while continue_ not in ['y', 'n']:
  83.             continue_ = input("输入无效!是否继续添加?(y/n)")

  84.     else:
  85.         print("学生信息录入完毕!")


  86. def search():
  87.     continue_ = 'y'
  88.     while continue_ == 'y':
  89.         if not isfile("students.pkl"):
  90.             print("没有任何数据!")
  91.             return
  92.         way = input("按ID查输入1;按姓名查输入2:")
  93.         while way not in ['1', '2']:
  94.             way = input("输入无效!按ID查输入1;按姓名查输入2:")
  95.         if way == '1':
  96.             students = pickle.load(open("students.pkl", "rb"))
  97.             ID = input("请输入学生 ID:")
  98.             result = []
  99.             for each in students:
  100.                 if each['id'] == ID:
  101.                     result.append(each)
  102.         else:
  103.             students = pickle.load(open("students.pkl", "rb"))
  104.             name = input("请输入学生姓名:")
  105.             result = []
  106.             for each in students:
  107.                 if each['name'] == name:
  108.                     result.append(each)
  109.         result_str = ''
  110.         result_str += 'ID'.center(6)
  111.         result_str += '姓名'.center(12)
  112.         result_str += '语文'.center(10)
  113.         result_str += '数学'.center(10)
  114.         result_str += '英语'.center(10)
  115.         result_str += '总成绩'.center(11)
  116.         for i in result:
  117.             result_str += "\n"
  118.             result_str += i['id'].center(6)
  119.             result_str += i['name'].center(12)
  120.             result_str += str(i['chinese']).center(12)
  121.             result_str += str(i['math']).center(12)
  122.             result_str += str(i['english']).center(12)
  123.             result_str += str(i['chinese'] + i['math'] +
  124.                               i['english']).center(13)
  125.         print(result_str)
  126.         continue_ = input("是否继续查询 (y/n)?")
  127.         while continue_ not in ['y', 'n']:
  128.             continue_ = input("输入无效!是否继续查询 (y/n)?")


  129. def delete():
  130.     if not isfile("students.pkl"):
  131.         print("没有学生信息!")
  132.         return
  133.     continue_ = 'y'
  134.     while continue_ == 'y':
  135.         show()
  136.         ID = input("请输入要删除的学生ID:")
  137.         students = pickle.load(open("students.pkl", "rb"))
  138.         result = []
  139.         for each in students:
  140.             if each['id'] == ID:
  141.                 result.append(each)
  142.         if not result:
  143.             print(f"没有找到ID为 {ID} 的学生信息...")
  144.             show()
  145.         else:
  146.             for i in result:
  147.                 students.remove(i)
  148.             if not students:
  149.                 remove("students.pkl")
  150.                 print(f"ID 为 {ID} 的学生已成功删除!不可继续删除!")
  151.                 return
  152.             else:
  153.                 pickle.dump(students, open("students.pkl", "wb"))
  154.                 print(f"ID 为 {ID} 的学生已成功删除!")
  155.         continue_ = input("是否继续删除 (y/n)?")
  156.         while continue_ not in ['y', 'n']:
  157.             continue_ = input("输入无效!是否继续删除 (y/n)?")


  158. def modify():
  159.     if not isfile("students.pkl"):
  160.         print("没有学生信息!")
  161.         return
  162.     show()
  163.     continue_ = 'y'
  164.     while continue_ == 'y':
  165.         ID = input("请输入要修改的学生ID:")
  166.         students = pickle.load(open("students.pkl", "rb"))
  167.         result = []
  168.         for each in students:
  169.             if each['id'] == ID:
  170.                 result.append(each)
  171.         if not result:
  172.             print(f"没有找到ID为 {ID} 的学生信息...")
  173.             show()
  174.         elif len(result) != 1:
  175.             print("ID 有相同的情况!")
  176.         else:
  177.             students.remove(result[0])
  178.             name = input("请输入名字:")
  179.             chinese = input("请输入语文成绩:")
  180.             while not is_float(chinese):
  181.                 chinese = input("输入无效!请重新输入语文成绩:")
  182.             chinese = float(chinese)
  183.             math = input("请输入数学成绩:")
  184.             while not is_float(math):
  185.                 math = input("输入无效!请重新输入数学成绩:")
  186.             math = float(math)
  187.             english = input("请输入英语成绩:")
  188.             while not is_float(english):
  189.                 english = input("输入无效!请重新输入英语成绩:")
  190.             english = float(english)

  191.             score = {'id': ID, 'name': name,
  192.                      'chinese': chinese, 'math': math, 'english': english}
  193.             students.append(score)
  194.             pickle.dump(students, open("students.pkl", "wb"))
  195.         continue_ = input("是否继续修改 (y/n)?")
  196.         while continue_ not in ['y', 'n']:
  197.             continue_ = input("输入无效!是否继续修改 (y/n)?")


  198. def sort():
  199.     if not isfile("students.pkl"):
  200.         print("没有学生信息!")
  201.         return
  202.     show()
  203.     reverse = input("请选择(0升序;1降序):")
  204.     while reverse not in ['0', '1']:
  205.         reverse = input("输入无效!请选择(0升序;1降序):")
  206.     reverse = bool(int(reverse))
  207.     students = pickle.load(open("students.pkl", "rb"))
  208.     way = input("请选择排序方式"
  209.                 "(1按语文成绩排序;"
  210.                 "2按数学成绩排序;"
  211.                 "3按英语成绩排序;"
  212.                 "0按总成绩排序):")
  213.     while way not in ['0', '1', '2', '3']:
  214.         way = input("输入无效!请选择排序方式"
  215.                     "(1按语文成绩排序;"
  216.                     "2按数学成绩排序;"
  217.                     "3按英语成绩排序;"
  218.                     "0按总成绩排序):")
  219.     if way == '0':
  220.         def condition(x):
  221.             return x['chinese'] + x['math'] + x['english']
  222.     elif way == '1':
  223.         def condition(x):
  224.             return x['chinese']
  225.     elif way == '2':
  226.         def condition(x):
  227.             return x['math']
  228.     else:
  229.         def condition(x):
  230.             return x['english']
  231.     result = sorted(students, key=condition, reverse=reverse)
  232.     result_str = ''
  233.     result_str += 'ID'.center(6)
  234.     result_str += '姓名'.center(12)
  235.     result_str += '语文'.center(10)
  236.     result_str += '数学'.center(10)
  237.     result_str += '英语'.center(10)
  238.     result_str += '总成绩'.center(11)
  239.     for i in result:
  240.         result_str += "\n"
  241.         result_str += i['id'].center(6)
  242.         result_str += i['name'].center(12)
  243.         result_str += str(i['chinese']).center(12)
  244.         result_str += str(i['math']).center(12)
  245.         result_str += str(i['english']).center(12)
  246.         result_str += str(i['chinese'] + i['math'] +
  247.                           i['english']).center(13)
  248.     print(result_str)


  249. def total():
  250.     try:
  251.         print("一共有",
  252.               str(len(pickle.load(open("students.pkl", "rb")))), "名学生!")
  253.     except FileNotFoundError:
  254.         print("没有学生信息!")


  255. def show():
  256.     if not isfile("students.pkl"):
  257.         print("没有学生信息!")
  258.         return
  259.     result = pickle.load(open("students.pkl", "rb"))
  260.     result_str = ''
  261.     result_str += 'ID'.center(6)
  262.     result_str += '姓名'.center(12)
  263.     result_str += '语文'.center(10)
  264.     result_str += '数学'.center(10)
  265.     result_str += '英语'.center(10)
  266.     result_str += '总成绩'.center(11)
  267.     for i in result:
  268.         result_str += "\n"
  269.         result_str += i['id'].center(6)
  270.         result_str += i['name'].center(12)
  271.         result_str += str(i['chinese']).center(12)
  272.         result_str += str(i['math']).center(12)
  273.         result_str += str(i['english']).center(12)
  274.         result_str += str(i['chinese'] + i['math'] +
  275.                           i['english']).center(13)
  276.     print(result_str)


  277. def is_float(number):
  278.     try:
  279.         float(number)
  280.     except ValueError:
  281.         return False
  282.     else:
  283.         return True


  284. if __name__ == '__main__':
  285.     try:
  286.         main()
  287.     except BaseException as e:
  288.         print("啊哦,出错了!")
  289.         print(e)
  290.         input("请按 <Enter> 键退出程序!")
复制代码

评分

参与人数 1荣誉 +5 鱼币 +5 贡献 +3 收起 理由
最后的魁拔 + 5 + 5 + 3

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2020-3-7 14:48:25 | 显示全部楼层
wuqramy 发表于 2020-3-7 14:32
还是@zltzlt 的功能全
这是Ta的代码(Python)

哈哈,用一下他的主界面就好看多了
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>

  4. typedef struct _node
  5. {
  6.     char name[64];
  7.     char id[10];
  8.     char score[64];
  9.     struct _node *next;
  10. } Node;

  11. typedef struct _list
  12. {
  13.     Node *head;
  14. } List;

  15. //--1--插入新的学生(头插法)
  16. void AddStudentByHead(List *list);
  17. //尾插法V1
  18. void AddStudentByEndV1(List *list);
  19. //尾插法V2只能单独使用
  20. void AddStudentByEndV2(List *list);
  21. void ChangeStudent(List *list, char *input);
  22. void Input(Node *p);
  23. int Search(List *list, char *input);
  24. void Delete(List *list, char *input);
  25. void PrintStudent(List *list);
  26. void ClearList(List *list);
  27. Node *PrintFlage(List *list, char *input);

  28. int main(void)
  29. {
  30.     List list;
  31.     list.head = NULL;
  32.     char code;
  33.     int c;
  34.     char input1[64];
  35.     char input2[64];
  36.     char input3[64];
  37.     int flag = 0;
  38.     Node *temp;
  39.     while (1)
  40.     {
  41.        printf("\n\
  42.         ╔———————————————学生信息管理系统————————————————╗\n\
  43.                                                         \n\
  44.         =============== 功能菜单 ================\n\
  45.                                             \n\
  46.         1 录入学生信息\n\
  47.         2 查找学生信息\n\
  48.         4 删除学生信息\n\
  49.         3 修改学生信息\n\
  50.         5 显示所有学生信息\n\
  51.         6 退出系统\n\
  52.        ==========================================\n\
  53.        说明:通过数字选择菜单\n\
  54.     ╚——————————————————————————————————————————————╝\n");

  55.         printf("请输入指令代码(1-6)\n");
  56.         do
  57.         {
  58.             scanf("%c", &code);
  59.         } while (code>54||code<49);
  60.         
  61.       

  62.         switch (code)
  63.         {

  64.         case '1':
  65.             printf("请选择插入学生的方法(1-头插法 2-尾插法V1):");
  66.             scanf("%d", &c);

  67.             switch (c)
  68.             {
  69.             case 1:
  70.                 AddStudentByHead(&list);
  71.                 break;
  72.             case 2:
  73.                 AddStudentByEndV1(&list);
  74.                 break;

  75.             default:
  76.                 printf("输入指令错误\n");
  77.             }
  78.             break;

  79.         case '2':
  80.             printf("请输入你要查找的学生:");
  81.             scanf("%s", input1);
  82.             flag = (Search(&list, input1));
  83.             if (flag > 0)
  84.             {
  85.                 temp = PrintFlage(&list, input1);
  86.                 printf("学生姓名:%s\t学号%s\t分数:%s\t", temp->name, temp->id, temp->score);
  87.             }
  88.             else
  89.             {
  90.                 printf("不好意思,查无此人\n");
  91.             }
  92.             break;

  93.         case '3':
  94.             printf("请输入你要更改的学生名字:");
  95.             scanf("%s", input2);
  96.             flag = Search(&list, input2);
  97.             temp = PrintFlage(&list, input2);
  98.             if (flag > 0)
  99.             {
  100.                 printf("当前的学生信息为:\n");
  101.                 printf("学生姓名:%s\t学号%s\t分数:%s\t", temp->name, temp->id, temp->score);
  102.                 printf("请输入您要更改的学生信息\n");
  103.                 ChangeStudent(&list, input2);
  104.             }
  105.             else
  106.             {
  107.                 printf("不好意思,你要更改的学生名字尚未存在\n");
  108.             }
  109.             break;

  110.         case '4':

  111.             printf("请输入你要删除的学生名字:");
  112.             scanf("%s", input3);
  113.             if (Search(&list, input3) > 0)
  114.             {
  115.                 Delete(&list, input3);
  116.             }
  117.             else
  118.             {
  119.                 printf("不好意思,你要删除的学生名字尚未存在\n");
  120.             }
  121.             break;

  122.         case '5':
  123.             PrintStudent(&list);
  124.             break;
  125.         case '6':
  126.             if (!list.head)
  127.             {
  128.                 printf("还没有信息呢\n");
  129.             }
  130.             goto END;

  131.         default:
  132.             printf("输入指令错误\n");
  133.             break;
  134.         }
  135.         printf("^__^\n");
  136.         printf("\n\n");
  137.     }
  138. END:
  139.     ClearList(&list), printf("删库跑路成功^__^\n");

  140.     system("pause");
  141.     return 0;
  142. }
  143. //--1--插入新的学生
  144. void AddStudentByHead(List *list)
  145. {
  146.     Node *p, *temp;
  147.     p = (Node *)malloc(sizeof(Node));
  148.     Input(p);

  149.     if (list->head)
  150.     {
  151.         temp = list->head;
  152.         list->head = p;
  153.         p->next = temp;
  154.     }
  155.     else
  156.     {
  157.         list->head = p;
  158.         p->next = NULL;
  159.     }
  160. }
  161. //尾插法
  162. void AddStudentByEndV1(List *list)
  163. {
  164.     Node *p;
  165.     p = (Node *)malloc(sizeof(Node ));
  166.     Input(p);

  167.     Node *last;
  168.     last = list->head;

  169.     if (last)
  170.     {
  171.         while (last->next)
  172.         {
  173.             last = last->next;
  174.         }
  175.         last->next = p;
  176.         p->next=NULL;
  177.     }
  178.     else
  179.     {
  180.         list->head = p;
  181.         p->next = NULL;
  182.     }
  183. }
  184. //尾插法
  185. /*
  186. void AddStudentByEndV2(List *list)
  187. {
  188.     Node *p;
  189.     p = (Node *)malloc(sizeof(Node ));
  190.     Input(p);
  191.     static Node *tail;

  192.     if (list->head)
  193.     {
  194.         tail=list->head;
  195.         tail->next = p;
  196.         p->next = NULL;
  197.     }
  198.     else
  199.     {
  200.         list->head = p;
  201.         p->next = NULL;
  202.     }

  203.     tail = p;
  204. }
  205. */
  206. void ChangeStudent(List *list, char *input)
  207. {
  208.     Node *p;
  209.     for (p = list->head; p; p = p->next)
  210.     {
  211.         if (!strcmp(p->name, input))
  212.         {
  213.             Input(p);
  214.             break;
  215.         }
  216.     }
  217. }
  218. void Input(Node *p)
  219. {
  220.     printf("请输入姓名:");
  221.     scanf("%s", p->name);
  222.     printf("请输入学号(2位数字):");
  223.     scanf("%s", p->id);
  224.     printf("请输入学生分数(小于1000):");
  225.     scanf("%s", p->score);
  226. }
  227. int Search(List *list, char *input)
  228. {
  229.     int flag = -1; //标志
  230.     Node *p;
  231.     for (p = list->head; p; p = p->next)
  232.     {
  233.         if (!strcmp(p->name, input))
  234.         {
  235.             flag = 1;
  236.             break;
  237.         }
  238.     }

  239.     return flag;
  240. }
  241. Node *PrintFlage(List *list, char *input)
  242. {
  243.     Node *p;
  244.     for (p = list->head; p; p = p->next)
  245.     {
  246.         if (!strcmp(p->name, input))
  247.         {

  248.             break;
  249.         }
  250.     }
  251.     return p;
  252. }
  253. void Delete(List *list, char *input)
  254. {
  255.     Node *p, *q = NULL;
  256.     for (p = list->head; p; q = p, p = p->next)
  257.     {
  258.         if (!strcmp(p->name,input))
  259.         {

  260.             if (q)
  261.             {
  262.                 q->next = p->next;
  263.                
  264.             }
  265.             else
  266.             {
  267.                 list->head = p->next;  
  268.             }
  269.             free(p);
  270.             break;
  271.         }
  272.         
  273.     }
  274. }
  275. void PrintStudent(List *list)
  276. {
  277.     Node *p;
  278.     for (p = list->head; p; p = p->next)
  279.     {
  280.         printf("学生姓名:%s\t学号:%s\t分数:%s\t\n", p->name, p->id, p->score);
  281.     }
  282. }
  283. //--6--删库跑路
  284. void ClearList(List *list)
  285. {
  286.     Node *p, *q;
  287.     for (p = list->head; p; p = q)
  288.     {
  289.         q = p->next;
  290.         free(p);
  291.     }
  292. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-5-8 14:51:23 | 显示全部楼层
大佬牛批
果断收藏
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-7-8 21:43:33 | 显示全部楼层
感谢分享学习了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-5-22 13:03:47 | 显示全部楼层
厉害
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-22 09:42

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表