Skip to main content

Create and display Doubly circular link list in c++ code

 Hi, guys code for creating and displaying doubly circular link list using c++ given below

#include<iostream>
using namespace std;
struct node {
    int data;
    node *next;
    node *prev;
};
struct node *tail,*head;
/*creating doubly circular link list*/
void createdcll() {
    node *newnode;
    int choice;
    head=0;
    while(choice!=0)
    {
        newnode=new node;
        cout<<"enter the dcll data"<<endl;
        cin>>newnode->data;
        if(head==0) {
            head=tail=newnode;
            head->next=head;
            head->prev=head;
        }
        else {
            tail->next=newnode;
            newnode->prev=tail;
            newnode->next=head;
            head->prev=newnode;
            tail=newnode;
        }
        cout<<"u wanna continue";
        cin>>choice;
    }
}
/*display doubly circular link list*/
void displaydcll() {
    cout<<"this is display"<<endl;
    node *temp=head;
    if(tail==0)
    {
        cout<<"empty list";

    }
    else {
        while(temp!=tail)
        {
            cout<<"data"<<temp->data<<endl;
            temp=temp->next;
        }
        cout<<"data"<<temp->data<<endl;
    }
}
main() {
    createdcll() ;
    displaydcll() ;

}


Comments

Popular posts from this blog

Print elements in sorted order from a row_column wise sorted matrix

  #include <iostream> using namespace std;   struct Node {     int val;      int r;      int c; };   void minHeapify(Node harr[], int i, int heap_size) {     int l = i * 2 + 1;     int r = i * 2 + 2;      if(l < heap_size&& r<heap_size && harr[l].val < harr[i].val && harr[r].val < harr[i].val){             Node temp=harr[r];             harr[r]=harr[i];             harr[i]=harr[l];             harr[l]=temp;             minHeapify(harr ,l,heap_size);             minHeapify(harr ,r,heap_size);         }           if (l < heap_size && harr[l].val < harr[i].val){             Node temp=harr[i];...

Reverse of an array using c and c++

 Hi, guys in this post we will see about  Reverse of an array using c and c++ * c++ code #include <iostream> using namespace std; //Compiler version g++ 6.3.0 int main() {     int a[5]={1,2,3,4,5};     int temp ;     int i=4;     int j=0;     for(i=4;i>5/2;i--)     {       temp=a[i];       a[i]=a[j];       a[j]=temp;       j++;            }     for(int k=0;k<5;k++){       cout<<a[k];     } }   C code #include<stdio.h> //Compiler version g++ 6.3.0 int main() {     int a[ 5 ]={ 1 , 2 , 3 , 4 , 5 };     int temp ;     int i= 4 ;     int j= 0 ;     for (i= 4 ;i> 5 / 2 ;i--)     {       temp=a[i];       a[i]=a[j]; ...