#include <iostream> #include <stdio.h> #include <stdlib.h> using namespace std; typedef struct node { int date; struct node *next; }cirNode,*Linklist; void creat_list(Linklist& T) { Linklist p, p1; const int n = 3; int a[n] = { 5, 11, 14 }; p1 = T; T->date = a[0]; for(int i=1;i<n;i++) { p=(Linklist)malloc(sizeof(cirNode)); p->next = NULL; p->date = a[i]; T->next = p; T=p; }; p->next = p1; } void display_list(Linklist& T)//输出链表 { Linklist tail = T; Linklist p = T->next; while (p != tail) { cout << p->date << endl; p = p->next; } if (p) cout << p->date << endl; cout << " ############ " << endl; } void merge_list(Linklist& T1, Linklist& T2) { cirNode *head = T1->next; T1->next = T2->next; T2->next = head; T1 = T2; } void main() { cirNode a; Linklist p1; p1 = &a; creat_list(p1); cirNode a2; Linklist p2; p2 = &a2; creat_list(p2); display_list(p1); merge_list(p1, p2); display_list(p1); }