write a program to implement stack using array

#include <iostream>
using namespace std;
int stack[100], n=100, top=-1;
void push(int val) {
   if(top>=n-1)
   cout<<"Stack Overflow"<<endl;
   else {
      top++;
      stack[top]=val;
   }
}
void pop() {
   if(top<=-1)
   cout<<"Stack Underflow"<<endl;
   else {
      cout<<"The popped element is "<< stack[top] <<endl;
      top--;
   }
}
void display() {
   if(top>=0) {
      cout<<"Stack elements are:";
      for(int i=top; i>=0; i--)
      cout<<stack[i]<<" ";
      cout<<endl;
   } else
   cout<<"Stack is empty";
}
int main() {
   int ch, val;
   cout<<"1) Push in stack"<<endl;
   cout<<"2) Pop from stack"<<endl;
   cout<<"3) Display stack"<<endl;
   cout<<"4) Exit"<<endl;
   do {
      cout<<"Enter choice: "<<endl;
      cin>>ch;
      switch(ch) {
         case 1: {
            cout<<"Enter value to be pushed:"<<endl;
            cin>>val;
            push(val);
            break;
         }
         case 2: {
            pop();
            break;
         }
         case 3: {
            display();
            break;
         }
         case 4: {
            cout<<"Exit"<<endl;
            break;
         }
         default: {
            cout<<"Invalid Choice"<<endl;
         }
      }
   }while(ch!=4);
   return 0;
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
1. Implement Stack Using Arrays program in java of stack using array how to create a stack with an array implementing a stack with an array array based stack operations explain the implementation of stack using array stack operations using array stack using array program implementing stack using array implement stack with array array using stack Write a Program to implement a Stack using arrays? &quot;Write 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&quot; how to create a stack using arrays should you implement a stack with an array how to create a stack using array explain array implementation of stack design and implement of stack using array to implement stack using array Build an Array With Stack Operations create a graph in stack in c++ using array write a program that implements stack using arrays how do you create a stack using an array c program for stack using array Write the C code to pop an element from the stack Write the C code to push an element (e) into the stack Write the C code to pop an element from the stack? Write the C code to push an element (e) into the stack? stack using array in c++ using struct simple stack in c stacks with arrays how to make stack of an array in c++ write a c program for stack using array push and pop operation in stack using c++ stack using procedure c++ stack using procedurec++ stack adt using array in c full stack using array code c++ C++ Program to Implement Stack using array implementing stak using array in cpp code to create a stack in c with output how to implement stack using array in c+_ stack creation in c code implementing stack using array in cpp Write a program implement stack using arrays program to insert an element into a stack using c implement stack adt using array in c write a c Program to implement stack data structure using array code to traverse the stack using Array. c++ Code to pop elements from stack using Array. C++ code to push element in a stack using Array. implement stack using array in cpp stacks using array stack with array in C stack with array inC stack with array stack in c using array convert an array to a stack c++ stack list as an array in C implwmwnt concept of push operation in c how to implement stack using array write an algorithm to implement stack using array implement stack using array in c stack using array in c cpp stack code Show implementation of Stack using array with size 5. Program for implementing Stack using array. in cpp array implementation of stack c++ lifo using array in c++ where should we implement stacks in c++ stack array implementation in c stack program in c++ stack implementation using array WAP to implement stack by using an array implement stack using array c++ program to implement stack using arrays . Write a program to implement stack methods using array implementing a stack using an array in c stack using array stack c++ program implementation of stack using array in c++ programs Write a program to demonstrate stack using arrays c++ program using stack create stack and insert element and display it in c++ stack using arrays stack using arrays in c++ stack using array in c++ stack implementation using array c++ stack implement using array Stack using an Array c++ implement array to stack in C++ stack in array in c push function for stack in c stack using array in c program push and pop c++ stack to array implementation of stack using array in c, user input stack program in c using array stack implementation using array in c programmiz implementation of stack using array in c implementing stack as an array in c create a stack using array and struct in c create a stack using array in c STACK USINGH ARRAY stack application program in c++ array implementation of stack c++ stack array based implementation implementation of stack using array in data structure in c stack by array in c++ stack implementation using array in c++ implementation of stacks using arrays in c stacks using arrays in c stack using array c++ stack implementation using array in c c stack array implementation Stack using array emlmntaion array implementation of stacks and queues using c stack using array implementationc Write a program to implement STACK using Array and perform PUSH and POP operations in C++ Write a program to implement STACK using Array and perform PUSH and POP operations. perform stack operation using array implementation stack using array in c using structure Implementation of Stack using Array implement stack using arrays program for implementation of stack using array code for stack using array in c Write a program to implementing a stack using an array. and to display the contents of the stack. how to create stack using array stack operations using c++ stack using array in cpp write a program to implement stack using array
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source