-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeck.cpp
75 lines (61 loc) · 1.37 KB
/
deck.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
// SELF
#include <deck.hpp>
// STANDARD LIBRARY
#include <iostream>
#include <vector>
Deck::Deck() {
this->cards = std::vector<int>();
}
Deck::Deck(int card) {
this->cards = {card};
}
int Deck::at(int i) const {
return this->cards.at(i);
}
std::vector<int>::iterator Deck::begin() {
return this->cards.begin();
}
std::vector<int>::iterator Deck::end() {
return this->cards.end();
}
std::ostream& operator<<(std::ostream &out, const Deck &deck) {
if(deck.size() == 0) {
out << "[]";
return out;
}
// TODO: consider refactoring
// write A instead of 11
if(deck.at(0) == 11) {
out << "[" << "A";
} else {
out << "[" << deck.at(0);
}
for(int i = 1; i < deck.size(); i++) {
// write A instead of 11
if(deck.at(i) == 11) {
out << ", " << "A";
} else {
out << ", " << deck.at(i);
}
}
out << "]";
return out;
}
int Deck::size() const {
return this->cards.size();
}
void Deck::clear() {
this->cards.clear();
}
void Deck::insert(int index, const int& val) {
std::vector<int>::iterator it = this->cards.begin();
this->cards.insert((it + index), val);
}
void Deck::push_back(const int& val) {
this->cards.push_back(val);
}
int Deck::pop_back() {
int out = this->cards.back();
this->cards.pop_back();
return out;
}