aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-12-05 16:09:45 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-12-05 16:09:45 +0800
commitaf1074a592e6cd246dd2db726ccc4eb6873e3ba4 (patch)
tree0e9a323648050f4f9814fc033f90c3504f213552 /src
parent2f828ddfb1f649f8ed53291bdaf9457c2f633f75 (diff)
downloadadvent-of-code-af1074a592e6cd246dd2db726ccc4eb6873e3ba4.tar.gz
advent-of-code-af1074a592e6cd246dd2db726ccc4eb6873e3ba4.zip
2022 day5
Diffstat (limited to 'src')
-rw-r--r--src/2022/day5/aoc.h14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/2022/day5/aoc.h b/src/2022/day5/aoc.h
index be1791e..1014bb7 100644
--- a/src/2022/day5/aoc.h
+++ b/src/2022/day5/aoc.h
@@ -1,5 +1,5 @@
#include "common.h"
-#include <vector>
+#include <stack>
namespace aoc2022 {
@@ -103,13 +103,13 @@ struct crate {
}
}
if (mode == 2) {
- std::vector<crate*> dx;
- for (int x = 0; x < d[0]; x++) {
- crate* c = take(d[1]);
- dx.push_back(c);
+ std::stack<crate*> dx;
+ while(d[0]-- > 0) {
+ dx.push(take(d[1]));
}
- for (auto s = dx.size(); s > 0; s--) {
- put(dx[s - 1], d[2]);
+ while(!dx.empty()) {
+ put(dx.top(), d[2]);
+ dx.pop();
}
}
}