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

#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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值