-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stack_Iterator.cpp
72 lines (61 loc) · 1.1 KB
/
Stack_Iterator.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
// Honor Pledge:
//
// I pledge that I have neither given nor
// received any help on this assignment.
//
// blakbenn
//#include "Stack_Iterator.h"
//
// Constructor
//
// curr_ begins at s.size() and will count down to zero for the iterator pattern
template <typename T>
Stack_Iterator<T>::Stack_Iterator (Stack <T> & s):
s_ (s), curr_ (s.size())
{
}
//
// Destructor
//
template <typename T>
Stack_Iterator<T>::~Stack_Iterator (void)
{
}
//
// is_done
//
template <typename T>
bool Stack_Iterator<T>::is_done (void)
{
//returns true when curr_ is less than or equal to 0
return this->curr_ <= 0;
}
//
// advance
//
template <typename T>
void Stack_Iterator<T>::advance (void)
{
//decrement curr_ and pop the stack
-- this->curr_;
s_.pop();
return;
}
//
// Overloaded * operator
//
template <typename T>
T Stack_Iterator<T>::operator * (void)
{
//get top of the stack
return this->s_.top();
}
//
// Overloaded -> operator
//
template <typename T>
T * Stack_Iterator<T>::operator -> (void)
{
//return address of the top of the stack
return &this->s_.top();
}