您的位置:首页 > 其它

小白第二步走-------双链表之学生信息录入系统(最简易)

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: