#include
#include
#include
#define LEN sizeof(struct stu)
struct stu *ins(struct stu *head, int num);
struct stu
{
int num;
int score;
struct stu *next;
} ;
void main()
{
int i, n = 0;
int num;
struct stu *p1, *p2, *head, *h;
p1 = p2 = (struct stu *) malloc(LEN);
scanf("%d %d", &p1->num, &p2->score);
while(p1->num)
{
n++;
if(n == 1)
{
head = p1;
}
else
{
p2->next = p1;
}
p2 = p1;
p1 = (struct stu *)malloc(LEN);
scanf("%d %d", &p1->num, &p1->score);
}
p2->next = NULL;
h = head;
while(head)
{
printf("%d %d\n", head->num, head->score);
head = head->next;
}
head = h;
printf("Input a number to insert: ");
scanf("%d", &num);
head = ins(head, num);
while(head)
{
printf("%d %d\n", head->num, head->score);
head = head->next;
}
}
struct stu *ins(struct stu *head, int num)
{
struct stu *pp1, *pp2;
pp1 = (struct stu *)malloc(LEN);
pp2 = (struct stu *)malloc(LEN);
if(num == 1)
{
scanf("input the score: %d", &pp1->score);
pp1->num = 1;
pp1->next = head;
head = pp1;
}
else
{
pp1 = head;
while(pp1->num != num&&pp1->next != NULL)
{
pp1 = pp1->next;
}
if(pp1->num != num&&pp1->next == NULL)
{
scanf("input the score: %d", &pp2->score);
pp2->num = num;
pp1->next = pp2;
pp2->next = NULL;
}
else
{
scanf("input the score: %d", &pp2->score);
pp2->num = num;
pp2->next = pp1->next;
pp1->next = pp2;
}
}
return head;
}
scanf("input the score: %d", &pp2->score);
->
printf("input the score:");
scanf("%d", &pp2->score);
别的类似