0% found this document useful (0 votes)
5 views1 page

Stack Push and Pop Implementation

This C++ code defines a stack class with push and pop functions. The stack uses an array to store elements and tracks the position of the top element. The main function creates a stack instance, pushes 10 integers onto the stack, then pops all elements off the stack in a loop.

Uploaded by

Saif khawaja
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Stack Push and Pop Implementation

This C++ code defines a stack class with push and pop functions. The stack uses an array to store elements and tracks the position of the top element. The main function creates a stack instance, pushes 10 integers onto the stack, then pops all elements off the stack in a loop.

Uploaded by

Saif khawaja
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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; [Link](1); [Link](2); [Link](3); [Link](4); [Link](5); [Link](6); [Link](7); [Link](8); [Link](9); [Link](10); for(int j=0;j<10;j++) { [Link](); } }

You might also like