Tuesday, January 19, 2010

STACK

#include
#include
#include
#include
#include
struct node
{
char info;
int data;
node *link;
}*top,*temp;
void main()
{
clrscr();
top=0;
int ch;
ch=0;
char c;
while(ch==0)
{
cout< cout<<"2:pop the elements of the stack"< cout<<"3:reverse the elements of the string"< cout<<"4:exit"< cout<<"enter your choice::";
cin>>ch;
switch(ch)
{
case 1:
{
do
{
temp=(node *)malloc(sizeof(node));
cout<<"enter the data/element::";
cin>>temp->data;
temp->link=top;
top=temp;
cout<<"do you still want to insert(y/n): ";
cin>>c;
}while (c=='y' || c=='Y');
if(c=='n' || c=='N')
{
ch=0;
break;
}
}

case 2:
{
int item;
if(top==0)
{
cout< ch=0;
break;
}
else
{
do
{
item=top->data;
top=top->link;
cout<<"deleted element is::"< cout< cin>>c;
}while((c=='y'|| c=='Y')&& top->data!=0);
if(c=='n' || c=='N')
{
ch=0;
break;
}
if(top==0)
{
cout< ch=0;
break;
}
}
}

case 3:
{
char item;
char a[20];
top=0;
cout< cin>>a;
for(int i=0;a[i]!='\0';i++)
{
temp=(node *)malloc(sizeof(node));
temp->info=a[i];
temp->link=top;
top=temp;
}
while(top!=0)
{
item=top->info;
top=top->link;
cout< }
cout< ch=0;
break;
}

case 4:
{
ch=5;
exit(0);
}

}
}
getch();
}

No comments: