DFS – DBLCIRCL

#include<iostream.h>
#include<conio.h>

struct node
{
int n;
node *nxt;
node *prv; //<-2->4
};

class link
{
node *ptr,*h,*tmp;
char ans;

public:

void create();
void display();
};
void link ::create()
{
h=NULL;

do
{
ptr=new node;
cout<<“Enter the value: “;
cin>>ptr->n;
ptr->prv=NULL;
ptr->nxt=NULL;
if(h==NULL)
{
h=ptr;
tmp=ptr;
}
else
{
tmp->nxt=ptr;
ptr->prv=tmp;

tmp=ptr;
}

cout<<“Do U want to enter the another value ? “;
cin>>ans;

}while(ans==’y’||ans==’Y’);

ptr->nxt=h;
h->prv=ptr;

}
void link::display()
{
ptr=h;

do
{
cout<<ptr->n<<“–>”;
ptr=ptr->nxt;
}while(ptr!=h);
}
main()
{
clrscr();
link ob;

ob.create();
ob.display();
getch();
}

Share

About the Author

Akash Padhiyar

Visit Website

There are no comments yet, add one below.

Leave a Comment

Your email address will not be published. Required fields are marked *

*

Time limit is exhausted. Please reload CAPTCHA.