-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.cpp
More file actions
116 lines (105 loc) · 2.48 KB
/
Copy pathstack.cpp
File metadata and controls
116 lines (105 loc) · 2.48 KB
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
116
/**
* @file stack.cpp
* Implementation of the Stack class.
*
* @author CS 225 Course Staff
* @date Fall 2009
*
* @author Chase Geigle
* @date Fall 2012
*/
/**
* Adds the parameter object to the top of the Stack. That is, the element
* should go at the beginning of the list.
*
* @note This function must be O(1)!
*
* @param newItem The object to be added to the Stack.
*/
template<class T>
void Stack<T>::push(T const & newItem)
{
myStack.push_back(newItem);
/**
* @todo Your code here!
*/
}
/**
* Removes the object on top of the Stack, and returns it. That is, remove
* the element at the beginning of the list. You may assume this function
* is only called when the Stack is not empty.
*
* @note This function must be O(1)!
*
* @return The element that used to be at the top of the Stack.
*/
template<class T>
T Stack<T>::pop()
{
/**
* @todo Your code here! You will have to replace the following line.
*/
T temp = myStack.back();
myStack.pop_back();
return temp;
}
/**
* Adds an element to the ordering structure.
*
* @see OrderingStructure::add()
*/
template <class T>
void Stack<T>::add( const T & theItem ) {
/**
* @todo Your code here! Hint: this should call another Stack function
* to add the element to the Stack.
*/
push (theItem);
}
/**
* Removes an element from the ordering structure.
*
* @see OrderingStructure::remove()
*/
template <class T>
T Stack<T>::remove() {
/**
* @todo Your code here! Hint: this should call another Stack function
* to remove an element from the Stack and return it. You will need to
* replace the following line.
*/
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. It should
* look at the beginning of the list. You may assume this function is only
* called when the Stack is not empty.
*
* @note This function must be O(1)!
*
* @return The element at the top of the Stack.
*/
template<class T>
T Stack<T>::peek()
{
/**
* @todo Your code here! You will need to replace the following line.
*/
return (myStack.back());
}
/**
* Determines if the Stack is empty.
*
* @note This function must be O(1)!
*
* @return Whether or not the stack is empty (bool).
*/
template<class T>
bool Stack<T>::isEmpty() const
{
/**
* @todo Your code here! You will need to replace the following line.
*/
return (myStack.empty());
}