#include
#include
typedef struct node
{
int num;
char name[100];
char sex[20];
int age;
struct node *next;
}Node, *List;
void input(List l)
{
Node *p, *cur;
cur = l;
while(1)
{
p = (Node*)malloc(sizeof(Node));
scanf("%d",&p->num);
if(p->num == -1)
{
free(p);
break;
}
scanf("%s%s%d",p->name, p->sex, &p->age);
cur ->next = p;
cur = p;
cur->next = NULL;
}
}
void show(List l)
{
Node *p = l->next;
while(p)
{
printf("%d %s %s %d,",p->num, p->name, p->sex, p->age);
p = p->next;
}
}
void del(List l, int n)
{
Node *last;
Node *p;
last = l;
p = l->next;
while(p)
{
if(p->age == n)
{
last ->next = p->next;
free(p);
p = last->next;
}
else
{
last = p;
p = p->next;
}
}
}
void destroy(List l)
{
if(l == NULL) return;
destroy(l->next);
free(l);
}
int main()
{
Node h = {};
int age;
List l =&h;
input(l);
show(l);
scanf("%d",&age);
del(l, age);
show(l);
destroy(l->next);
return 0;
}
是只能用链表实现是吗?你着急要吗,我下午有空的话帮你写下哈,或者晚上。
30元