#include <stdio.h>
#include <stdlib.h>
#include <ctime>
typedef struct node{
int data;
struct node *next, *rear;
}node, *CircularList;
int random(int min, int max);
void InitList(CircularList &C);
void TraverseList(CircularList C);
void MergeList(CircularList &C1, CircularList C2);
int main(){
CircularList C1, C2;
srand((unsigned int)time(NULL));
InitList(C1);
InitList(C2);
TraverseList(C1);
TraverseList(C2);
MergeList(C1, C2);
TraverseList(C1);
return 0;
}
int random(int min, int max){
return rand() % (max - min) + min;
}
void InitList(CircularList &C){
C = (CircularList)malloc(sizeof(node));
C->data = -1;
C->rear = C;
for (int i = 0; i < 6; i++){
node *p = (node*)malloc(sizeof(node));
p->data = random(1, 100);
C->rear->next = p;
C->rear = p;
}
C->rear->next = C;
}
void TraverseList(CircularList C){
node *p = C->next;
while (p != C){
printf("%d ", p->data);
p = p->next;
}
printf("\n");
}
void MergeList(CircularList &C1, CircularList C2){
C1->rear->next = C2->next;
C2->rear->next = C1;
free(C2);
C2 = NULL;
}
