write a program to implement stack using array

Solutions on MaxInterview for write a program to implement stack using array by the best coders in the world

showing results for - "write a program to implement stack using array"
Elouan
05 Jun 2018
1#include <iostream>
2using namespace std;
3int stack[100], n=100, top=-1;
4void push(int val) {
5   if(top>=n-1)
6   cout<<"Stack Overflow"<<endl;
7   else {
8      top++;
9      stack[top]=val;
10   }
11}
12void pop() {
13   if(top<=-1)
14   cout<<"Stack Underflow"<<endl;
15   else {
16      cout<<"The popped element is "<< stack[top] <<endl;
17      top--;
18   }
19}
20void display() {
21   if(top>=0) {
22      cout<<"Stack elements are:";
23      for(int i=top; i>=0; i--)
24      cout<<stack[i]<<" ";
25      cout<<endl;
26   } else
27   cout<<"Stack is empty";
28}
29int main() {
30   int ch, val;
31   cout<<"1) Push in stack"<<endl;
32   cout<<"2) Pop from stack"<<endl;
33   cout<<"3) Display stack"<<endl;
34   cout<<"4) Exit"<<endl;
35   do {
36      cout<<"Enter choice: "<<endl;
37      cin>>ch;
38      switch(ch) {
39         case 1: {
40            cout<<"Enter value to be pushed:"<<endl;
41            cin>>val;
42            push(val);
43            break;
44         }
45         case 2: {
46            pop();
47            break;
48         }
49         case 3: {
50            display();
51            break;
52         }
53         case 4: {
54            cout<<"Exit"<<endl;
55            break;
56         }
57         default: {
58            cout<<"Invalid Choice"<<endl;
59         }
60      }
61   }while(ch!=4);
62   return 0;
63}
queries leading to this page
methods of stack in c 2b 2bimport stack in c 2b 2bstack functionstack operations using c 2b 2bfunction call stack c 2b 2bstack with array in c 22write the code for a stack machine assume all operations occur on top of the stack push and pop are the only instructions that access memory 22show implementation of stack using array with size 5 implementation of stack using array in data structure in cprogram to implement stack using arraysstack usingh arraystack using an array c 2b 2bstack in cppshould you implement a stack with an arraystack list as an array in cc 2b 2b stack implementationstacks using array c 2b 2bimplementation of stacks using arrays in cc 2b 2b stack pop implementationstack by array in c 2b 2bstack with array incstack creation in c codec 2b 2b program to implement stack operationscpp stack codeimplementing stak using array in cppimplementing stack using array in cpparray implementation of stacks and queues using cstack using array in c 2b 2bwrite a c program for stack using arraystack implementation using arrayimplementation of stack using array in c 2b 2b programsstack implementc 2b 2b stack to arraystack c 2b 2b stlimplementing stackc 2b 2b program to implement stack using arrayprogram to insert an element into a stack using carray implementation of stack c 2b 2bstack using array implementationc stack operations program for implementation of stack using arrayc 2b 2b stack classimplwmwnt concept of push operation in cwap to implement stack using arraystack using arraystack in c 2b 2b using arraystack implement using arrayarray implementation of stackstack program in c 2b 2b using array1 09implement stack using arrayshow to create a stack using arraystack implementation using array in c programmizstack using array in cppc 2b 2b stack array based implementationstack implementation using array c 2b 2bstack in array in cwrite the c code to push an element 28e 29 into the stackimplementation of stackstack adt using array in cc 2b 2b stack arrayarray implementation of stack by c 2b 2beasy array stack c 2b 2bwrite the c code to pop an element from the stack 3fimplement stack with arraysimple stack in cwrite an algorithm to implement stack using arraystack using arrays in c 2b 2bstack cppprogram in java of stack using arrayarray using stackhow do you create a stack using an arrayrepresentation of stack using arraystack c 2b 2b is full stack funcstack stl c 2b 2bstack operations using arrayarray stack c 2b 2bimplementation of stack using array in cimplement stack adt using array in chow to use stack in cpparray based stack operationsstack using array programc 2b 2b program using stackc 2b 2b program to implement stack using arraysimplement stack stack explainedstacks using arrays in ccode to traverse the stack using array c 2b 2bpush function for stack in cwrite a program to implement stack using array and perform push and pop operations in c 2b 2bstack in c 2b 2bhow to implement stack using array in c 2b code to push element in a stack using array stack implementationwrite a program to implementing a stack using an array and to display the contents of the stack write a program implement stack using arraysimplementation of stack using array 28structures 29 in c 2b 2bstack in c using arrayhow to create a stack with an arrayimplementing a stack with an arraywrite a program to implement stack using array and perform push and pop operations create a stack using array in cstack 28 29 c 2b 2bhow to define stack in c 2b 2bimplement stack using array in cppcode for stack using array in ccode to pop elements from stack using array c 2b 2bc 2b 2b stacks using arraystack methodsimplementing stack using arraywrite the c code to pop an element from the stackexplain array implementation of stackimplementation of stack using arrays cppwrite a program to implement stack using arraycreate a stack using array and struct in cwrite a program that implements stack using arraysimplement stack using array stack using array in c using structurestack implementation using array in cimplementation of stack in cppstack operations problem c 2b 2bstack examplehow to make stack of an array in c 2b 2bstack using array in cstack application program in c 2b 2bstack program in c using arraywrite a c program to implement stack data structure using arraywhere should we implement stacks in c 2b 2bstack using array c 2b 2bstack program in c 2b 2bprogram for implementing stack using array in cppwrite the c code to push an element 28e 29 into the stack 3fimplementing a stack using an array in cimplement stack using array in cc 2b 2b stackstacks using arrayimplement stack using arrayshow to store an array elements in stackimplementing stack as an array in cstacks with arrays c 2b 2blifo using array in c 2b 2bc program for stack using arraypush and pop operation in stack using c 2b 2bstacks with arraysimplementing stack using array in c 2b 2bstack c 2b 2bstack in cpp using arrayhow to create stack using arraystack implementation in c 2b 2b using arraystack using array in c program push and popto implement stack using arraystack using array emlmntaionarray stack in c 2b 2bimplementation of stack using array in c 2c user inputcode to create a stack in c with outputstack in c 2b 2bstack with arraystack c 2b 2b programperform stack operation using array implementationwrite a program to implement a stack using arrays 3fwap to implement stack by using an arrayexplain the implementation of stack using arrayc stack array implementationstack array implementation in ccreate stack and insert element and display it in c 2b 2bstack implementation using array in c 2b 2bdesign and implement of stack using arrayhow to implement stack using arrayimplement stack using arraystack program in c 2b 2b using arrayliststack using arraysimplement array to stack in c 2b 2bstack using procedure c 2b 2bfull stack using array code c 2b 2bimplementation of stack using array write a program to implement stack methods using arraywrite a program to demonstrate stack using arraysarray in stack c 2b 2bstack add in c 2b 2bcan an array work as a stackbuild an array with stack operationscreate a graph in stack in c 2b 2b using arraystack using procedurec 2b 2bprogram to implement stack using arraystack implementation all operations using c 2b 2bconvert an array to a stack c 2b 2bhow to create a stack using arraysstack using array in c 2b 2b using structwrite a program to implement stack using array