-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStack.cpp
More file actions
75 lines (67 loc) · 918 Bytes
/
Copy pathStack.cpp
File metadata and controls
75 lines (67 loc) · 918 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include<iostream>
#include<cstdlib>
using namespace std;
#define SIZE 10
template <class X>
class Stack
{
X a[SIZE];
int top;
int size;
public:
Stack()
{
top=-1;
size=SIZE;
}
void push(X);
X pop();
bool isEmpty();
bool isFull();
};
template<class X>
void Stack<X>::push(X e)
{
/*
if(isFull())
{
cout<<"\n OverFlow \n Program Terminated";
exit(0);
}
*/
//cout<<"\n Inserting "<<e<<" in the Stack ";
a[++top]=e;
}
template<class X>
X Stack<X> :: pop()
{
X x;
/*
if(isEmpty())
{
cout<<"\n UnderFlow\n Program Terminated";
exit(0);
}
*/
x=a[top];
//cout<<"\n Element Poped is :"<<a[top];
top--;
return x;
}
template<class X>
bool Stack<X>:: isEmpty()
{
if(top==-1)
{
return 1;
}
else
{
return 0;
}
}
template<class X>
bool Stack<X> :: isFull()
{
return top == size - 1 ;
}