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
- 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
- How to Restrict Facebook friends using lists
- How to clean iPhone/iPad/iPod backup files
- Apple’s Siri On iPhone 4S vs Microsoft’s Tellme On Windows Phone
- Your Facebook account hacked? Here’s how to fix it
- Indian Railway Enabled VRM System to travel without the printout of e-ticket
Tags
apple
c and cpp
Cheats
download
downloads
Entertainment
error
Film
friendship
Fun
gadgets
Games
gmail
google
greetings
india
Internet
iphone
java script
linux
love
mac
microsoft
mobile
News
office
onam
Personal
photos
Programming
review
Security
software
source code
technology
Tips & Tricks
video
videos
virus
web
web development
windows
windows 7
worm
yahoo
Recent Comments
- salman on C++ Program Program for Binary Search.
- Mithun on C++ Program to implement a QUEUE using linked list
- The Tamale Chica Chronicles has moved! | Tamale Chica Chronicles on Get redirection script
- Aparajita Chaudhuri on C++ Program implement a stack using an array
- Harta on Disable Adobe CS4 Activation Check

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….