[go: up one dir, main page]

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

Stack (Push and Pop)

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)
68 views1 page

Stack (Push and Pop)

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
You are on page 1/ 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