/*
题 号 编程题 第5题
文 件 名 T1105.CPP
截止日期 期末考试前提交有效
试题内容 编写程序建立一个链表,每个结点包括:学号、姓名、年龄,输入一个学号,
如果链表中的结点包括该学号,则输出该结点内容后,并将其结点删去。
数据描述 连续输入学号int no、姓名char name[12]、年龄int age,结束学号输入0。再输入查找节点学号。
输出第1行为原链表,第2行为删除节点后的链表。
输入格式 101 zhang 18
102 wang 21
103 zhou 19
104 chen 20
105 huang 20
0
103
输出格式 101 102 103 104 105
101 102 104 105
*/
#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(struct STU)
struct STU
{
struct STU *next;
int num;
char name[12];
int age;
};
void main()
{
struct STU *p=NULL,*t=NULL,*head=NULL;
{
p=(struct STU *)malloc(LEN);head=p;
scanf("%d %s %d",&p->num,p->name,&p->age);
if(p->num==0)
goto loop;
p->next=NULL;
}
do{
t=p;
p=(struct STU *)malloc(LEN);
scanf("%d",&p->num);
if(p->num==0)
break;
scanf("%s %d",p->name,&p->age);
p->next=NULL;
t->next=p;
}while(1);
loop: int num;
scanf("%d",&num);
p=head;
while(p->next)
{printf("%d ",p->num);p=p->next;}printf("%d\n",p->num);
p=head;
if(p->num==num)
head=p->next;
while(p->next)
{
if(p->next->num==num)
{p->next=p->next->next;break;}
p=p->next;
}
p=head;
while(p->next)
{printf("%d ",p->num);p=p->next;}printf("%d",p->num);
}
/*
101 zhang 18
102 wang 21
103 zhou 19
104 chen 20
105 huang 20
0
103
*/