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
Post a Comment