@@ -29,6 +29,9 @@ template <class T, class D> class CompareStacks : public Problem<T, D> {
2929 std::cout << str << std::endl;
3030 }
3131
32+ // Redefinition
33+ void readPush (int iter = 1 );
34+
3235private:
3336 // Stack Functions: defined by user
3437 virtual D readInput (std::vector<std::string> line) = 0;
@@ -67,8 +70,7 @@ template <class T, class D> void CompareStacks<T, D>::runCompare(int buffer) {
6770 std::streampos position = Problem<T, D>::mInput .tellg ();
6871 (*Problem<T, D>::mStack ).setPosition (position);
6972 for (int i = 1 ; i <= buffer; i++) {
70- bool bIndex =
71- Problem<T, D>::top (i).mIndex == mNormalStack ->top (i).mIndex ;
73+ bool bIndex = Problem<T, D>::top (i).mIndex == mNormalStack ->top (i).mIndex ;
7274 bool bData = Problem<T, D>::top (i).mData == mNormalStack ->top (i).mData ;
7375 if (!bIndex || !bData) {
7476 Problem<T, D>::println ();
@@ -81,7 +83,7 @@ template <class T, class D> void CompareStacks<T, D>::runCompare(int buffer) {
8183 break ;
8284 }
8385 D data = readInput (line);
84- Problem<T, D>::mIndex ++; // Might have to move
86+ Problem<T, D>::mIndex ++;
8587 if ((*Problem<T, D>::mStack ).empty () != mNormalStack ->empty ()) {
8688 (*Problem<T, D>::mStack ).empty ();
8789 Problem<T, D>::println ();
@@ -97,8 +99,7 @@ template <class T, class D> void CompareStacks<T, D>::runCompare(int buffer) {
9799 bool bData = elt.mData == eltNormal.mData ;
98100 if (!bIndex || !bData) {
99101 Problem<T, D>::println ();
100- std::cout << *Problem<T, D>::mContext << std::endl;
101- ;
102+ // std::cout << *Problem<T, D>::mContext << std::endl;
102103 std::cout << mNormalStack ->toString () << std::endl;
103104 throw " The two elements popped are different" ;
104105 }
@@ -109,10 +110,35 @@ template <class T, class D> void CompareStacks<T, D>::runCompare(int buffer) {
109110 Problem<T, D>::push (elt);
110111 mNormalStack ->push (elt);
111112 }
113+ if (Problem<T, D>::mStack ->getBufferSize () > 0 ) {
114+ std::cout << " Is it working" << std::endl;
115+ for (int k = 1 ; k <= Problem<T, D>::mStack ->getBufferSize (); k++) {
116+ if (Problem<T, D>::mStack ->top (k).mIndex == mNormalStack ->top (k).mIndex ) {
117+ Problem<T, D>::println ();
118+ // std::cout << *Problem<T, D>::mContext << std::endl;
119+ std::cout << mNormalStack ->toString () << std::endl;
120+ throw " The two elements at the k = $(k) position are different" ;
121+ }
122+ }
123+ }
112124 }
113125 } catch (char const *e) {
114126 std::cout << e << std::endl;
115127 }
116128}
117129
130+ template <class T , class D > void CompareStacks<T, D>::readPush(int iter) {
131+ for (int i = 0 ; i < iter; i++) {
132+ std::streampos position = Problem<T, D>::mInput .tellg ();
133+ Problem<T, D>::mStack ->setPosition (position);
134+ std::vector<std::string> line = Problem<T, D>::readLine ();
135+ D data = readInput (line);
136+ Problem<T, D>::mIndex ++;
137+ Data<T, D> elt (Problem<T, D>::mIndex , data);
138+ pushAction (elt);
139+ Problem<T, D>::push (elt);
140+ mNormalStack ->push (elt);
141+ }
142+ }
143+
118144#endif /* COMPARE */
0 commit comments