-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.cpp
80 lines (73 loc) · 1.48 KB
/
stack.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
#include "ordering_structure.h"
/**
* @file stack.cpp
* Implementation of the Stack class.
*
*/
/**
* Adds the parameter object to the top of the Stack.
*
* @param newItem The object to be added to the Stack.
*/
template<class T>
void Stack<T>::push(T const & newItem)
{
myStack.pushR(newItem);
}
/**
* Removes the object on top of the Stack, and returns it.
* the element at the beginning of the list. You may assume this function
* is only called when the Stack is not empty.
*
* @return The element from the top of the Stack.
*/
template <class T>
T Stack<T>::pop()
{
if(!isEmpty()){
return myStack.popR();
}
}
/**
* Adds an element to the ordering structure.
*
* @see OrderingStructure::add()
*/
template <class T>
void Stack<T>::add(const T& theItem)
{
push(theItem);
}
/**
* Removes an element from the ordering structure.
*
* @see OrderingStructure::remove()
*/
template <class T>
T Stack<T>::remove()
{
return pop();
}
/**
* Finds the object on top of the Stack, and returns it to the caller.
* Unlike pop(), this operation does not alter the Stack itself.
* You may assume this function is only
* called when the Stack is not empty.
*
* @return The value of the element at the top of the Stack.
*/
template <class T>
T Stack<T>::peek()
{
return myStack.peekR();
}
/**
* Determines if the Stack is empty.
*
* @return Whether or not the stack is empty (bool).
*/
template <class T>
bool Stack<T>::isEmpty() const
{
return myStack.isEmpty();
}