Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions Stacks_Using_Queues/stacks using static array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include<iostream>
using namespace std;

class stack
{
private:
int top;
public:
stack()
{
top=-1;
}
int arr[10];
void push(int n)
{
if(top>=10-1)
{
cout<<"stack overflow"<<endl;
}
else
{
top++;
arr[top]=n;
cout<<arr[top];
cout<<endl;
}
}
int pop()
{
if(top<0)
cout<<"stack empty"<<endl;
else
{

return arr[top--];
}

}
};
int main()
{
stack a;
cout<<"pushing"<<endl;
a.push(10);
a.push(20);
a.push(30);
cout<<"popping"<<endl;
cout<<a.pop()<<endl;
cout<<a.pop()<<endl;
cout<<a.pop()<<endl;
// cout<<a.pop()<<endl;
return 0;
}