-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.h
115 lines (57 loc) · 1.35 KB
/
stack.h
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef STACK_H_
#define STACK_H_
#include"dllist.h"
// Stack ADT using linked list as primary data structure.
//
template<typename Type>
class Stack {
public:
Stack();
// Basic stack operations
void push(Type item);
void pop();
Type peek() const;
// Check to see if there is anything on the stack
bool empty() const;
// Use to see what is in the stack for debugging
void print() const;
#ifndef MAKE_MEMBERS_PUBLIC
private:
#endif
DLList<Type> list;
};
// Stack Implementation
//
// Stack() Default constrcutor:
// Call the defualt constructor for its List.
// Already implemented.
template<typename Type>
Stack<Type>::Stack():list() {}
template<typename Type>
void Stack<Type>::push(Type item) {
/* TODO */
list.insert_front(item);
}
template<typename Type>
void Stack<Type>::pop() {
/* TODO */
if(!empty()) {
list.remove_front();
}
}
template<typename Type>
bool Stack<Type>::empty() const {
/* TODO */
return list.empty();
}
template<typename Type>
Type Stack<Type>::peek() const {
/* TODO */
return list.peek_front();
}
template<typename Type>
void Stack<Type>::print() const {
/* TODO */
return list.print();
}
#endif//STACK_H__X_XMMXX