Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Stack(push and pop)

#include<iostream>
using namespace std; class stack { private: int position; int arry[10]; public: stack() { position=-1; //so the stack is empty } void push(int x) //push function { position++; arry[position]=x; } void pop() //pop function { cout<<arry[position--]; } }; void main() { stack s1; s1.push(1); s1.push(2); s1.push(3); s1.push(4); s1.push(5); s1.push(6); s1.push(7); s1.push(8); s1.push(9); s1.push(10); for(int j=0;j<10;j++) { s1.pop(); } }

You might also like