what is a stack in programming
A stack is an array or list structure of function calls and parameters used in modern computer programming
what is a stack in programming
A stack is an array or list structure of function calls and parameters used in modern computer programming
how to implement stack
#include<bits/stdc++.h>
using namespace std;
int Stack[100],n,top,i;
void push(int x) {
if(top<n-1) {
top++;
Stack[top]=x;
} else {
cout<<"Could not insert data, Stack is full.\n";
}
}
int pop() {
int data;
if(top>-1) {
data = Stack[top];
top = top - 1;
return data;
} else {
cout<<"Could not retrieve data, Stack is empty.\n";
}
}
void display()
{
if(top>=0)
{
cout<<"\n The elements in STACK \n";
for(i=top; i>=0; i--)
cout<<Stack[i]<<" ";
}
else
{
cout<<"\n The STACK is empty";
}
}
int main()
{
cin>>n;
top=-1;
push(10);
push(20);
push(40);
push(10);
cout<<endl<<pop();
display();
return 0;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us