-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.h
More file actions
105 lines (95 loc) · 2.47 KB
/
Copy pathstack.h
File metadata and controls
105 lines (95 loc) · 2.47 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
/**
* @file stack.h
* Definition of the Stack class.
*
* You **should not** modify this file for the MP!
*
* @author CS 225 course staff
* @date Spring 2007
*
* @author Daniel Hoodin
* @date Spring 2008
*
* @author Chase Geigle
* @date Fall 2012
*/
#ifndef STACK_H
#define STACK_H
#include <list>
using std::list;
#include "ordering_structure.h"
/**
* Stack class: represents a standard stack. Templated to hold elements of
* any type.
*
* You **should not** modify this file for the MP!
*
* @author CS 225 course staff
* @date Spring 2007
*
* @author Daniel Hoodin
* @date Spring 2008
*
* @author Chase Geigle
* @date Fall 2012
*/
template<class T>
class Stack : public OrderingStructure<T> {
public:
/**
* 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.
*/
void push( const T & newItem );
/**
* 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.
*/
T pop();
/**
* Adds an element to the ordering structure.
*
* @see OrderingStructure::add()
*/
void add( const T & theItem );
/**
* Removes an element from the ordering structure.
*
* @see OrderingStructure::remove()
*/
T remove();
/**
* 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.
*/
T peek();
/**
* Determines if the Stack is empty.
*
* @note This function must be O(1)!
*
* @return Whether or not the stack is empty (bool).
*/
bool isEmpty() const;
private:
list<T> myStack; /**< The list representing our Stack: the front of the list
corresponds to the top of the Stack.
@see http://www.cplusplus.com/reference/stl/list/ */
};
#include "stack.cpp" // needed for template instantiation
#endif