Nov
28
2008
28
2008
C++ Program implement a stack using an array
C++ Program implement a stack using an array.
/**************************************************************
Author: Arun Vishnu M V
Web: www.arunmvishnu.com
Description: C++ Program implement a stack using an array
***************************************************************/
#include<conio.h>
#include<iostream.h>
#include<process.h>
void main()
{
int stack[150],top,n,i,max_stack,choice,element,n_pop;
max_stack=150;
cout<<"How many elements are in the stack: ";
cin>>n;
cout<<"Enter "<>stack[top];
cout<<"\nStack is implemented.\nThe stack is\n";
for(i=top-1;i>=0;i--)
cout<>choice;
switch(choice)
{
case 1: // PUSH
cout<<"\nPUSH OPERATION\n";
if(top>=max_stack)
{
cout<<"Stack is full!";
getch();
break;
}
cout<<"Enter an element: ";
cin>>element;
stack[top]=element;
top++;
cout<<"Item Inserted!";
getch();
break;
case 2: // POP
cout<<"POP OPERATION\n";
if(top<0)
{
cout<<"Stack is empty";
getch();
break;
}
cout<<"How many elements you want to pop: ";
cin>>n_pop;
if(n_pop>top)
{
cout<<"\nError!\nStack is small.";
getch();
break;
}
top=top-n_pop;
cout<<"Items POPed";
getch();
break;
case 3: // Display
cout<<"\The stack is\n";
for(i=top-1;i>=0;i--)
cout<< stack[i] <<" ";
getch();
break;
case 4:
exit(0);
getch();
default:
cout<<"RE-enter your choice!";
} // End of switch
} // End of while
getch();
}
//---------------------- END--------------------
Related Posts
Latest Posts
- Google Account Activity gives you a monthly summary of your account activity across many Google products
- Apple released iOS 5.1
- You won’t be actually able to take 41MP photos using Nokia 808 PureView
- Apple Releases Mac OS X Mountain Lion 10.8 Developer Preview
- A walk down memory lane
- What is the real meaning of Facebook “Like”?
- Wish you and your family a very Happy and Prosperous New Year 2012!
- Import Orkut’s albums to Google+
- Download 100 Paid Android Apps(Like Fruit Ninja HD, BW, Smart Office etc. )For Free
- List Of Samsung Devices Getting Official Android 4.x Ice Cream Sandwich Update
Tags
apple
c and cpp
Cheats
download
downloads
Entertainment
Film
friendship
Fun
gadgets
Games
gmail
google
greetings
india
Internet
ipad
iphone
java script
linux
love
mac
microsoft
mobile
News
office
Orkut
Personal
photos
Programming
review
Security
software
source code
technology
Tips & Tricks
video
videos
virus
web
web development
windows
windows 7
worm
yahoo
Recent Comments
- Vikesh Kumar on C++ Program for QUICK SORT
- pratikchavan on C++ Program for QUICK SORT
- suraj on C++ Program Program for Binary Search.
- saravanan on Enabling REGEDIT and Task Manager
- VP on I Got My GirlFriend

An article by
sorry, your programs are just awesome but this one contain a bug in 12 th line
ohhh yea.. thx Anoop.. it caused when i edited it for formating in web
..
Hi Mr.Arun,
Warm Greetings.
I am presently studing BSc-IT and am preparing for my semester exams which will be commencing from 5th July’10 onwards.
Unfortunately, our university failed to upload the lab questions list on Data Structures using C++ during the beginning of the semester due to some technical reasons..Therefore I am in trouble as I could not get program codes for 11 programs (Questions) from that very list and my faculty is on sick leave.
Please help me….Thank you in advance
nice….keep it up
plz give me o/p of this stack array prog
Can I get each and every program of C++ in this website ?
i AM IN A ds LAB DUNNO ANYTHIN ABOUT IT :d ha ha ha
hi.,
mr.Arun sir ….
I’m a student of B.Tech.II nd year.of computer science…i want to do some new..plz help me………
mr.Arun sir,cn dis program be done in some other way?????please tell me the logic behind it…..is dis always necessary to use push n pop function……please tell me the logic in detail…
Some code formatting plugins used in this site making some issues in the code.. Few lines of codes were hidden due to the same issue. Cleared the cache and now you will get the complete program.
hi sir,
i am doing my ECE second year IN CHENNAI.i dont have an idea about writing a program in datastructures(array implementation,pointer implementation of list,stack),can u please help me with the basics and can u send me the program with brief explanation?
if you send me the program it would be really helpful to me.thank you…..
plzz give me this programmme by multilevel inheritence in c++ code….