44/* ==============================================================================
55 Includes
66==============================================================================*/
7- #include " problem.hpp"
87#include " data.hpp"
8+ #include " problem.hpp"
99
1010/* ==============================================================================
1111 Class : abstract, template (T context, D datas)
1414 Friends ->
1515 <- Problem
1616==============================================================================*/
17- template <class T , class D >
18- class CompareStacks : public Problem <T,D>{
17+ template <class T , class D > class CompareStacks : public Problem <T, D> {
1918public:
2019 // Members functions
21- CompareStacks<T,D>(std::string fileName);
20+ CompareStacks<T, D>(std::string fileName);
2221
2322 // Compare the stacks
2423 void runCompare (int buffer = 0 );
2524
2625 // IO
27- void printCompare (){
28- std::string str = Problem<T,D>::toString ();
26+ void printCompare () {
27+ std::string str = Problem<T, D>::toString ();
2928 str += " \n " + (*mNormalStack ).toString ();
3029 std::cout << str << std::endl;
3130 }
@@ -35,85 +34,83 @@ class CompareStacks: public Problem<T,D>{
3534 virtual D readInput (std::vector<std::string> line) = 0;
3635 virtual std::shared_ptr<T> initStack () = 0;
3736 virtual bool popCondition (D data) = 0;
38- virtual void popAction (Data<T,D> elt) {};
37+ virtual void popAction (Data<T, D> elt){};
3938 virtual bool pushCondition (D data) = 0;
40- virtual void pushAction (Data<T,D> elt) {};
39+ virtual void pushAction (Data<T, D> elt){};
4140
4241 // pop
43- Data<T,D> popCompare ();
42+ Data<T, D> popCompare ();
4443
4544 // Stack: Normal Stack for comparison
46- std::shared_ptr<NormalStack<T,D>> mNormalStack ;
45+ std::shared_ptr<NormalStack<T, D>> mNormalStack ;
4746};
4847
4948/* ==============================================================================
5049 Constructors :
5150==============================================================================*/
5251
5352template <class T , class D >
54- CompareStacks<T,D>::CompareStacks(std::string fileName)
55- : Problem<T,D>(fileName)
56- , mNormalStack (new NormalStack<T,D> ()){
57- }
53+ CompareStacks<T, D>::CompareStacks(std::string fileName)
54+ : Problem<T, D>(fileName), mNormalStack (new NormalStack<T, D>()) {}
5855
5956/* ==============================================================================
6057 Stack Functions: run, push, pop, top
6158==============================================================================*/
62- template <class T , class D >
63- Data<T,D> CompareStacks<T,D>::popCompare(){
64- return Problem<T,D>::mStack ->pop (*this );
59+ template <class T , class D > Data<T, D> CompareStacks<T, D>::popCompare() {
60+ return Problem<T, D>::mStack ->pop (*this );
6561}
6662
67- template <class T , class D >
68- void CompareStacks<T,D>::runCompare(int buffer){
63+ template <class T , class D > void CompareStacks<T, D>::runCompare(int buffer) {
6964 try {
70- Problem<T,D>::initStackIntern ();
71- while ((Problem<T,D>::mInput .good ())) {
72- std::streampos position = Problem<T,D>::mInput .tellg ();
73- (*Problem<T,D>::mStack ).setPosition (position);
65+ Problem<T, D>::initStackIntern ();
66+ while ((Problem<T, D>::mInput .good ())) {
67+ std::streampos position = Problem<T, D>::mInput .tellg ();
68+ (*Problem<T, D>::mStack ).setPosition (position);
7469 for (int i = 1 ; i <= buffer; i++) {
75- bool bIndex = Problem<T,D>::top (i).mIndex == mNormalStack ->top (i).mIndex ;
76- bool bData = Problem<T,D>::top (i).mData == mNormalStack ->top (i).mData ;
70+ bool bIndex =
71+ Problem<T, D>::top (i).mIndex == mNormalStack ->top (i).mIndex ;
72+ bool bData = Problem<T, D>::top (i).mData == mNormalStack ->top (i).mData ;
7773 if (!bIndex || !bData) {
78- Problem<T,D>::println ();
74+ Problem<T, D>::println ();
7975 std::cout << mNormalStack ->toString () << std::endl;
8076 throw " The top $(i)st elements are different" ;
8177 }
8278 }
83- std::vector<std::string> line = Problem<T,D>::readLine ();
84- if ( (line.front ()== " -1" ) || (line.front ()== " " ) ) {
79+ std::vector<std::string> line = Problem<T, D>::readLine ();
80+ if ((line.front () == " -1" ) || (line.front () == " " )) {
8581 break ;
8682 }
8783 D data = readInput (line);
88- Problem<T,D>::mIndex ++; // Might have to move
89- if ((*Problem<T,D>::mStack ).isempty () != mNormalStack ->isempty ()) {
90- (*Problem<T,D>::mStack ).isempty ();
91- Problem<T,D>::println ();
84+ Problem<T, D>::mIndex ++; // Might have to move
85+ if ((*Problem<T, D>::mStack ).empty () != mNormalStack ->empty ()) {
86+ (*Problem<T, D>::mStack ).empty ();
87+ Problem<T, D>::println ();
9288 std::cout << mNormalStack ->toString () << std::endl;
93- (*Problem<T,D>::mStack ).isempty ();
89+ (*Problem<T, D>::mStack ).empty ();
9490 throw " One stack is empty and not the other" ;
9591 }
96- while ( (!(Problem<T,D>::emptystack ())) && (popCondition (data)) ) {
97- Data<T,D> elt = Problem<T,D>::pop ();
98- Data<T,D> eltNormal = mNormalStack ->pop ();
92+ while ((!(Problem<T, D>::emptystack ())) && (popCondition (data))) {
93+ Data<T, D> elt = Problem<T, D>::pop ();
94+ Data<T, D> eltNormal = mNormalStack ->pop ();
9995 popAction (elt);
10096 bool bIndex = elt.mIndex == eltNormal.mIndex ;
10197 bool bData = elt.mData == eltNormal.mData ;
10298 if (!bIndex || !bData) {
103- Problem<T,D>::println ();
104- std::cout << *Problem<T,D>::mContext << std::endl;;
99+ Problem<T, D>::println ();
100+ std::cout << *Problem<T, D>::mContext << std::endl;
101+ ;
105102 std::cout << mNormalStack ->toString () << std::endl;
106103 throw " The two elements popped are different" ;
107104 }
108105 }
109106 if (pushCondition (data)) {
110- Data<T,D> elt (Problem<T,D>::mIndex ,data);
107+ Data<T, D> elt (Problem<T, D>::mIndex , data);
111108 pushAction (elt);
112- Problem<T,D>::push (elt);
109+ Problem<T, D>::push (elt);
113110 mNormalStack ->push (elt);
114111 }
115112 }
116- } catch (char const * e) {
113+ } catch (char const *e) {
117114 std::cout << e << std::endl;
118115 }
119116}
0 commit comments