已有a,b两个链表,每个链表中的结点包括学号、成绩。要求把两个链表合并,按学号升序排列。
#include <stdio.h>
#include <stdlib.h>typedef struct Node {long num;float score;struct Node* next;
} Node;Node* creat() {Node *head = NULL, *p1, *p2;p1 = p2 = (Node*)malloc(sizeof(Node));scanf("%ld,%f", &p1->num, &p1->score);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,%f", &p1->num, &p1->score);}p2->next = NULL;return head;
}void print(Node* head) {Node* p = head;while (p != NULL) {printf("Num: %ld, Score: %.1f\n", p->num, p->score);p = p->next;}
}Node* merge(Node* a, Node* b) {Node dummy;Node* tail = &dum