小白第二步走-------双链表之学生信息录入系统(最简易)
2015-10-11 22:58
323 查看
#include<stdio.h> #include<stdlib.h> #include<string.h> struct list_student { struct list_student * next,* prev; char name[10]; int age; int score; int sex; }; typedef struct list_student list; int k = 0; int a; main() { list * head; head = (list *)malloc(sizeof(list)); initial(head); printf("\t\t STUDENT INFORMATION TABLE 1.0\t\t\n"); printf("\tNAME\t\tSCORE\t\tAGE\t\tSEX\n"); printf("which service dou you choice:1 create 2 add 3 delete 4 change 5 print\n"); scanf("%d",&a); getchar(); choice(head); } initial(list * head) { head->next = NULL; head->prev = NULL; } screen(list * head) { printf("which service do you choice:1 create 2 add 3 delete 4 change 5 print\n"); scanf("%d",&a); getchar(); choice(head); } create(list * head) { list * p,* q; p = head; char j; char s; printf("do you want to start:y/n\n"); scanf("%c",&j); getchar(); if (j == 'y' ) { q = (list *)malloc(sizeof(list)); printf("let us put something in:\n"); scanf("%s %d %d %d",q->name,&q->score,&q->age,&q->sex); getchar(); p->next = q; q->prev = p; q->next = NULL; p = q; k = 1; printf("continue inputting?y/n\n"); scanf("%c",&s); getchar(); while(s == 'y') { q = (list *)malloc(sizeof(list)); scanf("%s %d %d %d",q->name,&q->score,&q->age,&q->sex); getchar(); p->next = q; q->prev = p; q->next = NULL; p = q; printf("continue inputting?y/n\n"); scanf("%c",&s); getchar(); k++; } if(s == 'n' ) { printf("that's all!\n"); } } if(j == 'n') { printf("That's all!\n"); } } print(list * head) { list * p; p = head->next; int g = 1; while(p != NULL) { printf("%d:%s,%d,%d,%d\n",g++,p->name,p->score,p->age,p->sex); p = p->next; } } add(list * head) { list * p,* q,* new, * o; p = head; new = (list *)malloc(sizeof(list)); int i; int j; printf("the place you want to add:\n"); scanf("%d",&i); getchar(); if(i>k) { printf("wrong number!\n"); } for(j = 1;j < i; j++) { p = p->next; } q = p->next; o = q->next; if(o == NULL) { q->next = new ; new->prev = q; } else { q->next = new; new->next = o; o->prev = new; new->prev = q; } printf("what you want to add in:\n"); scanf("%s %d %d %d",new->name,&new->score,&new->age,&new->sex); k++; } delete(list * head) { list * p,* q; p = head; int i,j; printf("which one you want to delet:\n"); scanf("%d",&i); getchar(); if(i>k) { printf("wrong number!\n"); } else { for(j = 1;j<i;j++) { p = p->next; } q = p->next; p->next = q->next; q->next = NULL; free(q); } } change(list * head) { list * p,* q; p=head; int i,j; printf("which one you want to change:\n"); scanf("%d",&i); getchar(); if(i>k) { printf("wrong number!\n"); } else { for(j=1;j<i;j++) { p=p->next; } } q=p->next; printf("input the thing you want to change:\n"); scanf("%s %d %d %d",q->name,&q->score,&q->age,&q->sex); getchar(); } choice(list * head) { switch(a) { case 1: create(head); screen(head);break; case 2: add(head);screen(head); break; case 3: delete(head);screen(head); break; case 4: change(head); screen(head);break; case 5: print(head); screen(head);break; default : exit(1); } } //in scanf %s ',' can be read in //when int k in whole .c,void **(int k) can let k be anyone
相关文章推荐
- 关于责任、钱和技术
- 计算机的启动引导过程
- 路由重分发
- HDU 5122 K.Bro Sorting (贪心)
- self容易出错的编程小问题
- MySQL学习笔记1:安装和登录
- sql基本语句
- STL之简单空间适配器实现
- Android应用的自动更新模块
- google product
- 扫描线 n块菜地最大利润种菜(重叠区域种最贵) hdu3255 Farming
- session_start
- 欢迎使用CSDN-markdown编辑器
- Oracle Flashback技术之Flashback Drop
- 6:装饰模式
- 访问者(Visitor Pattern)
- 详解JS闭包
- C语言全局变量初始化、数据类型长度
- js数组的操作
- Android中的四种动画(一)