Lead node # include <iostream>using namespace std;typedef int elemtype;typedef struct node{elemtype data; struct Node *next;} Lnode,*linklist; void Initlist (linklist &l); void Createcylist (linklist l); void Output (linklist l); int listlength (linklist l); bool Preelem (linklist l,elemtype e,elemtype &pre); Linklist mergecylist (linklist la,linklist lb); int main (int argc, char const *argv[]) {/* linklist l; Initlist (l); Createcylist (l); Output (l); cout<< "Len:" <<listlength (L) <<endl; int x; if (Preelem (l,20,x) ==true) cout<< "20 precursor element is" <<x<<endl; */linklist L1,L2; Initlist (L1); Initlist (L2); Createcylist (L1); Createcylist (L2); Linklist p = mergecylist (L1,L2); Output (p); return 0;} void Initlist (linklist &l) {L = new Lnode; L->next = L;} void Createcylist (linklist l) {cout<< "Enter the data in turn and use 1 as the closing tag: \ n"; int m; Lnode *p = l; while (1) {cin>>m; if (m==-1) Break Lnode *s = new Lnode; S->data = m; P->next = s; p = s; } P->next = l;} void Output (linklist l) {Lnode *p; p = l->next; while (p!=l) {cout<<p->data<< ""; p = p->next; } cout<< "\ n";} int Listlength (linklist l) {Lnode *p; p = l->next; int len = 0; while (p!=l) {len++; p = p->next; } return len; BOOL Preelem (linklist l,elemtype e,elemtype &pre) {Lnode *p,*q; p = l->next; Q = p->next; while (Q!=l->next) {if (q->data==e) {pre = p->data; return true; } p = q; Q = q->next; } return false;} Linklist mergecylist (linklist la,linklist Lb) {Lnode *p,*q; p=la,q=lb; while (P->next!=la) p = p->next; while (q->next!=lb) q = q->next; Q->next = La;p->next = lb->next; Delete Lb; return La;}
Circular link List