stack implementation
Sat Nov 13 2021 09:48:26 GMT+0000 (Coordinated Universal Time)
Saved by
@Naredra
#include<bits/stdc++.h>
using namespace std;
#define SIZE 5
int a[SIZE];
int front =-1;
void push(int data)
{
if(front==SIZE-1)
{
std::cout << "stack is full" << std::endl;
}
else{
front++;
a[front]=data;
}
}
//function to pop
void pop()
{
if(front==-1)
{
cout<<"not element to pop";
}
else
{
//cout<<a[front];
front--;
}
}
void show()
{
for(int i =0 ;i<=front;i++)
{
cout<<a[i];
cout<<endl;
}
}
int main()
{
push(2);
push(3);
push(4);
show();
pop();
show();
}
content_copyCOPY
Comments