-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicStack.cpp
More file actions
61 lines (60 loc) · 1.01 KB
/
BasicStack.cpp
File metadata and controls
61 lines (60 loc) · 1.01 KB
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
57
58
59
60
61
#include <iostream>
using namespace std;
class Stack{
private:
int size,top=-1;
int *arry;
public:
Stack(int size)
{
this->size=size;
arry=new int[size];
}
void print()
{
if(top!= -1)
{
cout<<"Value is :- "<<arry[top]<<endl;
}
else{
cout<<"No value (Stack is empty)."<<endl;
}
}
void push(int value)
{
if(top<size)
{
top++;
arry[top]=value;
}
else{
cout<<"Stack is full."<<endl;
}
}
int pop()
{
if(top!=-1)
{
top--;
}
else{
cout<<"Stack is empty."<<endl;
}
}
};
int main() {
// Write C++ code here
Stack stack=Stack(5);
stack.print();
stack.push(2);
stack.push(4);
stack.push(6);
stack.push(8);
stack.push(10);
stack.push(12);
stack.push(14);
stack.print();
stack.pop();
stack.print();
return 0;
}