#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(); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter