#include<stdio.h> #include<stdlib.h> typedef int ElemType; typedef struct LNode{ ElemType data; struct LNode *next; }LNode,*LinkList; bool InitList(LinkList &L) { L=(LNode*)malloc(sizeof(LNode)); if(L==NULL) return false; L->next=L; return true; } bool Empty(LinkList L) { if(L->next=L) return true; else return false; } bool isTail(LinkList L,LNode *p) { if(p->next=L) return true; else return false; } //尾插法 LinkList List_TailInsert(LinkList &L) { ElemType x; L=(LinkList)malloc(sizeof(LNode)); LNode *s,*r=L; printf("请输入单链表各个节点,以9999结束!\n"); scanf("%d",&x); while(x!=9999) { s=(LNode*)malloc(sizeof(LNode)); s->data=x; r->next=s; r=s; scanf("%d",&x); } r->next=L; return L; } //合并两个循环单链表要求合并后仍然保持循环单链表形式 LinkList Link(LinkList &h1,LinkList &h2){ LNode *p,*q; p=h1; while(p->next!=h1) p=p->next; q=h2; while(q->next!=h2) q=q->next; p->next=h2->next; q->next=h1; return h1; } int main(){ LinkList L1,L2; LinkList R,S,SS;//接收输入数据和处理完的B R=List_TailInsert(L1); S=List_TailInsert(L2); SS=Link(R,S); LNode *p=SS; while(p->next!=SS){ p=p->next; printf("->%d",p->data); } }