-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.cpp
More file actions
54 lines (45 loc) · 842 Bytes
/
stack.cpp
File metadata and controls
54 lines (45 loc) · 842 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
#include "stack.h"
template <class T>
Stack<T> :: Stack() {
num = 0;
topNode = NULL;
}
template <class T>
Stack<T> :: ~Stack() {
clear();
}
template <class T>
void Stack<T> :: push(const T it) {
Node <T> * tep = new Node<T>(it,topNode);
topNode = tep;
num++;
}
template <class T>
bool Stack<T> :: pop() {
Node <T> * tep;
if(num == 0) return false;
num--;
tep = topNode;
topNode = topNode->next;
delete tep;
return true;
}
template <class T>
T Stack<T> :: top() {
return topNode->value;
}
template <class T>
bool Stack<T> :: isEmpty() {
if(num == 0) return true;
return false;
}
template <class T>
void Stack<T> :: clear() {
Node <T> * tmp;
while(topNode != NULL) {
tmp = topNode;
topNode = topNode->next;
delete tmp;
}
num = 0;
}