"write a program to implement stack using array" Code Answer's
You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "write a program to implement stack using array" answered properly. Developers are finding an appropriate answer about write a program to implement stack using array related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like write a program to implement stack using array. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on write a program to implement stack using array.
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;
}
Source: www.tutorialspoint.com
All those coders who are working on the C++ based application and are stuck on write a program to implement stack using array can get a collection of related answers to their query. Programmers need to enter their query on write a program to implement stack using array related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about write a program to implement stack using array for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of write a program to implement stack using array while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "write a program to implement stack using array". Visit this developer's friendly online web community, CodeProZone, and get your queries like write a program to implement stack using array resolved professionally and stay updated to the latest C++ updates.