BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan

BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan (http://bzupages.com/)
-   Data Structure (http://bzupages.com/32-data-structure/)
-   -   program of single array acting as multiple stacks (http://bzupages.com/f32/program-single-array-acting-multiple-stacks-1051/)

taha khan 24-10-2008 12:19 AM

program of single array acting as multiple stacks
 
Code:

#include
using namespace std;
int stack[20],value,n;
int top1=-1;int top2=9;
void push(int stack[],int& top1,int& top2,int value)
{if(n==1)
{if(top1==9)
cout<<"stack1 is full"< else
{cout<<"enter value";
cin>>value;
stack[++top1]=value;
}
}
else if(n==2)
{if(top2==19)
cout<<"stack2 is full"< else
{cout<<"enter value";
cin>>value;
stack[++top2]=value;
}
}
}
void pop(int stack[],int& top1,int& top2,int value)
{if(n==3)
{if(top1==-1)
cout<<"stack1 is empty"< else
cout<<"popped element frm stack 1 is "< }else if(n==4)
{if(top2==9)
cout<<"stack 2 is empty"< else
cout<<"poped value frm stack 2 is "< }
}
void show(int stack[])
{if(n==5)
{cout<<"stack 1 is"< if(top1==-1)
cout<<"empty"< else
for(int i=0;i<=9;i++)
{if(stack[i]==0)
break;
cout< }
}
if(n==6)
{cout<<"stack 2 is"< if(top2==9)
cout<<"empty"< else
for(int i=10;i<=19;i++)
{if(stack[i]==0)
break;
cout< }
}
}
void main()
{
for(char k='y';k!='n';)
{cout<<"Press 1 to insert the element in stack 1,\n 2 to insert the element in stack 2,\n 3 to delet the element from stack 1,\n 4 to delet the element from stack 2,\n 5 to show stack 1,\n 6 to show stack 2,\n";
cin>>n;
if(n==1)
push(stack,top1,top2,value);
if(n==2)
push(stack,top1,top2,value);
if(n==3)
pop(stack,top1,top2,value);
if(n==4)
pop(stack,top1,top2,value);
if(n==5)
show(stack);
if(n==6)
show(stack);
cout<<"do u want more y/n??"< cin>>k;
}
}


.BZU. 24-10-2008 07:02 AM

Re: program of sngle array acting as multiple stacks
 
thanks Taha, your first contribution..
you welcome on the site..:smitten:

almahmood_pk 28-10-2008 09:06 PM

Re: program of sngle array acting as multiple stacks
 
Thanks Betty.
:book1:


All times are GMT +5. The time now is 07:13 AM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.