建立一个链表,每个结点包括:学号、姓名、性别、年龄。输入一个年龄,如果链表中的结点所包含的年龄等于此年龄,则将此结点删去。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Node {
long num;
char name[20];
char gender[10];
int age;
struct Node* next;
} Node;
Node* creat() {
Node *head = NULL, *p1, *p2;
p1 = p2 = (Node*)malloc(sizeof(Node));
scanf("%ld %s %s %d", &p1->num, p1->name, p1->gender, &p1->age);
int n = 0;
while (p1->num != 0) {
n++;
if (n == 1) head = p1;
else p2->next = p1;
p2 = p1;
p1 = (Node*)malloc(sizeof(Node));
scanf("%ld %s %s %d", &p1->num, p1->name, p1->gender, &p1->age);
}
p2->next = NULL;
return head;
}
void print(Node* head) {
Node* p = head;
while (p != NULL) {
printf("Num: %ld, Name: %s, Gender