-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_using_array.cpp
More file actions
56 lines (48 loc) · 973 Bytes
/
Copy pathstack_using_array.cpp
File metadata and controls
56 lines (48 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
class MyStack
{
public:
int *arr;
int cap;
int top;
MyStack(int c)
{
cap=c;
arr=new int [cap];
top=-1;
}
void push(int x){
if(top==cap-1){cout<<"Stack is full"<<endl;return;}
top++;
arr[top]=x;
}
int pop(){
if(top==-1){cout<<"Stack is Empty"<<endl;return INT_MIN;}
int res=arr[top];
top--;
return res;
}
int peek(){
if(top==-1){cout<<"Stack is Empty"<<endl;return INT_MIN;}
return arr[top];
}
int size(){
return (top+1);
}
bool isEmpty(){
return top==-1;
}
};
int main()
{
MyStack s(5);
s.push(5);
s.push(10);
s.push(20);
cout<<s.pop()<<endl;
cout<<s.size()<<endl;
cout<<s.peek()<<endl;
cout<<s.isEmpty()<<endl;
return 0;
}