#include<iostream.h>
#include<conio.h>
/*struct node
{
int n;
struct node *next;
}*first,*temp,*temp1;*/
class list
{
struct node
{
int n;
node *next;
}*first,*temp,*temp1;
public:
list()
{
first=NULL;
}
void operator+()
{
temp=new node;
cout<<"Enter value";
cin>>temp->n;
if(first==NULL)
{
temp->next=NULL;
first=temp;
}
else
{
temp1=first;
while(temp1->next->n<temp->n && temp1->next!=NULL)
{
temp1=temp1->next;
}
if(temp1==first && temp1->n>temp->n)
{
temp->next=first;
first=temp;
}
else
{
temp->next=temp1->next;
temp1->next=temp;
}
}
}
void display()
{
if(first==NULL)
{
cout<<"Stack is empty";
return;
}
temp=first;
while(temp!=NULL)
{
cout<<temp->n;
temp=temp->next;
}
}
};
void main()
{
char ch;
list l;
clrscr();
do
{
+l;
l.display();
cout<<"\nDo you want to contiune(Y/N):";
cin>>ch;
}while(ch=='y' || ch=='Y');
l.display();
getch();
}
No comments:
Post a Comment