Skip to content

Commit 35dcf1a

Browse files
committed
Added a readPush(int iter = 0) function for initStack()
1 parent 005dbce commit 35dcf1a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

include/problem.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ template <class T, class D> class Problem {
3939
// Running the stack
4040
void run();
4141
void run(int limit);
42+
void readPush(int iter = 1);
4243
void push(Data<T, D> elt);
4344
Data<T, D> pop();
4445
Data<T, D> top(int k);
@@ -202,7 +203,7 @@ std::vector<std::string> Problem<T, D>::readHeader() {
202203
}
203204

204205
/*==============================================================================
205-
Stack Functions: run, push, pop, top
206+
Stack Functions: run, push, pop, top, readPush
206207
==============================================================================*/
207208
template <class T, class D> void Problem<T, D>::run() {
208209
initStackIntern();
@@ -249,6 +250,19 @@ template <class T, class D> void Problem<T, D>::run(int limit) {
249250
}
250251
}
251252

253+
template <class T, class D> void Problem<T, D>::readPush(int iter) {
254+
for (int i = 0; i < iter; i++) {
255+
std::streampos position = mInput.tellg();
256+
(*mStack).setPosition(position);
257+
std::vector<std::string> line = readLine();
258+
D data = readInput(line);
259+
mIndex++;
260+
Data<T, D> elt(mIndex, data);
261+
pushAction(elt);
262+
push(elt);
263+
}
264+
}
265+
252266
template <class T, class D> void Problem<T, D>::push(Data<T, D> elt) {
253267
mStack->push(elt);
254268
}

0 commit comments

Comments
 (0)