-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.cpp
More file actions
62 lines (47 loc) · 970 Bytes
/
Stack.cpp
File metadata and controls
62 lines (47 loc) · 970 Bytes
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
#include "Stack.h"
#include "Object.h"
using namespace std;
Stack::Stack() { }
Stack::Stack(const Stack& orig) { }
Stack::~Stack() { }
Object * Stack::push(Object * object) {
data.push_back(object);
return this->peek();
}
Object * Stack::pop() {
Object * top = this->peek();
data.pop_back();
return top;
}
list<Object*> Stack::pop(unsigned int amount) {
list<Object*> popped;
for (unsigned int i = 0; i < amount; i++) {
popped.push_front(this->pop());
}
return popped;
}
Object * Stack::peek() const {
return data.back();
}
Object * Stack::top() const {
return data.back();
}
int Stack::size() const {
return data.size();
}
void Stack::mark() {
for (Object * item : data)
item->mark();
}
auto Stack::begin() const {
return data.begin();
}
auto Stack::begin() {
return data.begin();
}
auto Stack::end() const {
return data.end();
}
auto Stack::end() {
return data.end();
}