Circular link List

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.