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

Register FAQ Community Calendar New Posts Navbar Right Corner
HOME BZU Mail Box Online Games Radio and TV Cricket All Albums
Go Back   BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan > Institute of Computing > Bachelor of Science in Information Technology > BsIT 3rd Semester > Data Structure

Data Structure Lectures by Sir Ahsan..


Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 24-10-2008, 12:19 AM
taha khan's Avatar
Toddler

 
Join Date: Oct 2007
Location: Mumtaaz Abad Multan
Age: 34
Posts: 22
Class Roll Number: 07-06
taha khan will become famous soon enough
Send a message via Yahoo to taha khan
Default program of single array acting as multiple stacks

Code:
#include<iostream>
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"<<endl;
else
{cout<<"enter value";
cin>>value;
stack[++top1]=value;
}
}
else if(n==2)
{if(top2==19)
cout<<"stack2 is full"<<endl;
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"<<endl;
else
cout<<"popped element frm stack 1 is "<<stack[top1--]<<endl;
}else if(n==4)
{if(top2==9)
cout<<"stack 2 is empty"<<endl;
else
cout<<"poped value frm stack 2 is "<<stack[top2--]<<endl;
}
}
void show(int stack[])
{if(n==5)
{cout<<"stack 1 is"<<endl;
if(top1==-1)
cout<<"empty"<<endl;
else
for(int i=0;i<=9;i++)
{if(stack[i]==0)
break;
cout<<stack[i]<<endl;
}
}
if(n==6)
{cout<<"stack 2 is"<<endl;
if(top2==9)
cout<<"empty"<<endl;
else
for(int i=10;i<=19;i++)
{if(stack[i]==0)
break;
cout<<stack[i]<<endl;
}
}
}
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??"<<endl;
cin>>k;
}
}

Reply With Quote
  #2  
Old 24-10-2008, 07:02 AM
.BZU.'s Avatar


 
Join Date: Sep 2007
Location: near Govt College of Science Multan Pakistan
Posts: 9,693
Contact Number: Removed
Program / Discipline: BSIT
Class Roll Number: 07-15
.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute
Default Re: program of sngle array acting as multiple stacks

thanks Taha, your first contribution..
you welcome on the site..
__________________
(¯`v´¯)
`*.¸.*`

¸.*´¸.*´¨) ¸.*´¨)
(¸.*´ (¸.
Bzu Forum

Don't cry because it's over, smile because it happened
Reply With Quote
  #3  
Old 28-10-2008, 09:06 PM
almahmood_pk's Avatar
I like My BSIT

 
Join Date: Nov 2007
Location: Multan,Mouza Nandla
Posts: 6
Contact Number: 03017460896
Program / Discipline: BIT
Class Roll Number: 07-41
almahmood_pk is on a distinguished road
Send a message via Yahoo to almahmood_pk
Default Re: program of sngle array acting as multiple stacks

Thanks Betty.

Reply With Quote
Reply

Tags
acting, array, multiple, program, single, sngle, stacks



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array program in C sharp thecool Visual Programming 0 17-06-2011 08:59 PM
A Program to find number in an array JuNaiDiQbaL Object Oriented Programming 0 06-05-2011 10:32 PM
Program to enter 10 integers in a single-dimension array and then print out the array in ascending order bonfire Object Oriented Programming 0 09-03-2011 12:23 AM
Program to find the Sum of all elements in an Array (By Sheraz) .BZU. Visual Programming 0 15-12-2009 11:00 PM
Program to find the Minimum Number in an Array .BZU. Visual Programming 0 15-12-2009 10:57 PM

Best view in Firefox
Almuslimeen.info | BZU Multan | Dedicated server hosting
Note: All trademarks and copyrights held by respective owners. We will take action against any copyright violation if it is proved to us.

All times are GMT +5. The time now is 07:51 AM.
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.