#include <stdio.h>
typedef struct student {
int num;
int score;
struct student *next;
} STU;
STU *creat() {
STU *head, *p, *p1;
head = NULL;
p = (STU *)malloc(sizeof(STU));
scanf("%d%d", &p->num, &p->score);
if (p->num != 0) head = p;
while (p->num != 0) {
p1 = p;
p = (STU *)malloc(sizeof(STU));
scanf("%d%d", &p->num, &p->score);
p1->next = p;
}
p1->next = NULL;
return head;
}
void print(STU *head) {
STU *p;
p = head;
if (head == NULL) printf("List is empty!");
else
do {
printf("%d %d\n", p->num, p->score);
p = p->next;
} while (p != NULL);
}
STU *insert(STU *head, STU *x) {
STU *p0, *p1, *p2;
p1 = head;
p0 = x;
if (head == NULL) {
head = p0;
p0->next = NULL;
} else {
while (p0->num > p1->num && p1->next != NULL) {
p2 = p1;
p1 = p1->next;
}
if (p0->num < p1->num) {
if (head == p1) {
head = p0;
p0->next = p1;
} else {
p2->next = p0;
p0->next = p1;
}
} else {
p1->next = p0;
p0->next = NULL;
}
}
return head;
}
STU *delete (STU *head, int num) {
STU *p1, *p2;
if (head == NULL) {
printf("\n list null!\n");
return head;
}
p1 = head;
while (num != p1->num && p1->next != NULL) {
p2 = p1;
p1 = p1->next;
}
if (num == p1->num)
if (p1 == head) head = p1->next;
else p2->next = p1->next;
else printf("%d not been found!", num);
return head;
}
int main() {
STU *head, x;
int num;
head = creat();
print(head);
printf("Input the insert record:\n");
scanf("%d%d", &x.num, &x.score);
head = insert(head, &x);
print(head);
printf("Input the delete number:");
scanf("%d", &num);
head = delete (head, num);
print(head);
}