DFS :: Reverse List

#include<iostream.h>
#include<conio.h>
struct node
{
int n;
node *p;
};

class link
{
node *a,*b,*h,c;
char ans;

public:
void create();
void display();

};
void link::create()
{

h=NULL;
do
{
a=new node;
cout<<“enter the value”;
cin>>a->n;
a->p=NULL;
if(h==NULL)
{
h=a;
b=a;

}
else
{
a->p=b;
b=a;
}

cout<<“do u want to enter the value:”;
cin>>ans;

}while(ans==’Y’||ans==’y’);
}
void link::display()
{
a=b;
do

{

cout<<a->n<<“->”;
a=a->p;
}
while(a!=NULL);
}
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.