0% found this document useful (0 votes)
57 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)
57 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy