STACK DSA 70
STACK DSA 70
#include <iostream>
struct stack{
public:
int top;
int arr[max];
stack(){
top =-1;
if (top>=max-1){
cout<<"stack overflow"<<endl;
else{
arr[++top]= x;
int pop(){
if (top<0){
cout<<"stack underflow"<<endl;
return -1;
else{
int x = arr[top];
top--;
return x;
}
STACK IMPLEMENTATION USING ARRAY
int peek(){
if (top<0){
return -1;
else{
return arr[top];
bool isempty(){
if (top<0){
return 1;
else {
return 0;
void display(){
cout<<arr[i]<<" ";
};
int main() {
stack s;
int n;
cin>>n;
STACK IMPLEMENTATION USING ARRAY
int x;
for(int i=0;i<n;i++){
cin>>x;
s.push(x);
int y;
cin>>y;
for(int i=0;i<y;i++){
s.pop();
s.display();
cout<<endl;
if(s.isempty()){
else{
cout<<"stack is empty"<<endl;
return 0;
OUTPUT