Skip to content

Commit

Permalink
Merge pull request #21 from zerodays39/main
Browse files Browse the repository at this point in the history
Created Stack program in c++
  • Loading branch information
div-bargali authored Oct 6, 2020
2 parents 4576de5 + e84405e commit 2502ae6
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions C++/Data-Structures/Stack.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <bits/stdc++.h> //we are using cp header
using namespace std;

void showstack(stack <int> s) //function for stack
{
while (!s.empty())
{
cout << '\t' << s.top();
s.pop();
}
cout << '\n';
}

int main ()
{
stack <int> s; // declaring stack
s.push(10); //pushing elements
s.push(30);
s.push(20);
s.push(5);
s.push(1);

cout << "The stack is : ";
showstack(s); //calling our stack function

cout << "\ns.size() : " << s.size();
cout << "\ns.top() : " << s.top();


cout << "\ns.pop() : ";
s.pop();
showstack(s);

return 0;
}


/*
Output:
The stack is : 1 5 20 30 10
s.size() : 5
s.top() : 1
s.pop() : 5 20 30 10
*/

0 comments on commit 2502ae6

Please sign in to comment.