-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stack_full.cpp
94 lines (70 loc) · 1.3 KB
/
Stack_full.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
using namespace std;
int Stack[10], Top=0, MaxSize=10;
bool isEmpty()
{
return (Top == 0);
}
bool isFull()
{
return (Top == MaxSize);
}
bool push(int Element)
{
if( isFull() )
{
cout << "Stack is Full\n";
return false;
}
Stack[ Top++ ] = Element;
cout<< Element <<" is inserted into the Stack successfully.\n";
return true;
}
bool pop()
{
if( isEmpty() )
{
cout << "Stack empty\n";
return false;
}
Top--;
cout << "Pop operation is performed successfully.\n";
return true;
}
int topElement()
{
return Stack[ Top - 1 ];
}
void show()
{
if(isEmpty())
{
cout << "Stack empty\n";
return;
}
cout << "\n---------- STACK ELEMENTS ----------\n";
for( int i=Top-1; i>=0; i-- )
{
cout << Stack[i] << endl;
}
cout<<endl<<endl;
}
int main()
{
push(5);
push(6);
push(7);
push(8);
push(9);
push(10);
show();
cout<<"\nTop Element of the Stack: " << topElement() << endl;
pop();
pop();
cout<<"\nTop Element of the Stack: " << topElement() << endl;
show();
pop();
cout<<"\nTop Element of the Stack: " << topElement() << endl;
show();
return 0;
}