5
5
Includes
6
6
==============================================================================*/
7
7
#include " data.hpp"
8
- #include " problem .hpp"
8
+ #include " stackAlgo .hpp"
9
9
10
10
/* ==============================================================================
11
11
Class : abstract, template (T context, D datas)
12
12
Extensions :
13
13
Aliases :
14
14
Friends ->
15
- <- Problem
15
+ <- StackAlgo
16
16
==============================================================================*/
17
- template <class T , class D > class CompareStacks : public Problem <T, D> {
17
+ template <class T , class D > class CompareStacks : public StackAlgo <T, D> {
18
18
public:
19
19
// Members functions
20
20
CompareStacks<T, D>(std::string fileName);
@@ -24,7 +24,7 @@ template <class T, class D> class CompareStacks : public Problem<T, D> {
24
24
25
25
// IO
26
26
void printCompare () {
27
- std::string str = Problem <T, D>::toString ();
27
+ std::string str = StackAlgo <T, D>::toString ();
28
28
str += " \n " + (*mNormalStack ).toString ();
29
29
std::cout << str << std::endl;
30
30
}
@@ -54,68 +54,68 @@ template <class T, class D> class CompareStacks : public Problem<T, D> {
54
54
55
55
template <class T , class D >
56
56
CompareStacks<T, D>::CompareStacks(std::string fileName)
57
- : Problem <T, D>(fileName), mNormalStack (new NormalStack<T, D>()) {}
57
+ : StackAlgo <T, D>(fileName), mNormalStack (new NormalStack<T, D>()) {}
58
58
59
59
/* ==============================================================================
60
60
Stack Functions: run, push, pop, top
61
61
==============================================================================*/
62
62
template <class T , class D > Data<T, D> CompareStacks<T, D>::popCompare() {
63
- return Problem <T, D>::mStack ->pop (*this );
63
+ return StackAlgo <T, D>::mStack ->pop (*this );
64
64
}
65
65
66
66
template <class T , class D > void CompareStacks<T, D>::runCompare(int buffer) {
67
67
try {
68
- Problem <T, D>::initStackIntern ();
69
- while ((Problem <T, D>::mInput .good ())) {
70
- std::streampos position = Problem <T, D>::mInput .tellg ();
71
- (*Problem <T, D>::mStack ).setPosition (position);
68
+ StackAlgo <T, D>::initStackIntern ();
69
+ while ((StackAlgo <T, D>::mInput .good ())) {
70
+ std::streampos position = StackAlgo <T, D>::mInput .tellg ();
71
+ (*StackAlgo <T, D>::mStack ).setPosition (position);
72
72
for (int i = 1 ; i <= buffer; i++) {
73
- bool bIndex = Problem <T, D>::top (i).mIndex == mNormalStack ->top (i).mIndex ;
74
- bool bData = Problem <T, D>::top (i).mData == mNormalStack ->top (i).mData ;
73
+ bool bIndex = StackAlgo <T, D>::top (i).mIndex == mNormalStack ->top (i).mIndex ;
74
+ bool bData = StackAlgo <T, D>::top (i).mData == mNormalStack ->top (i).mData ;
75
75
if (!bIndex || !bData) {
76
- Problem <T, D>::println ();
76
+ StackAlgo <T, D>::println ();
77
77
std::cout << mNormalStack ->toString () << std::endl;
78
78
throw " The top $(i)st elements are different" ;
79
79
}
80
80
}
81
- std::vector<std::string> line = Problem <T, D>::readLine ();
81
+ std::vector<std::string> line = StackAlgo <T, D>::readLine ();
82
82
if ((line.front () == " -1" ) || (line.front () == " " )) {
83
83
break ;
84
84
}
85
85
D data = readInput (line);
86
- Problem <T, D>::mIndex ++;
87
- if ((*Problem <T, D>::mStack ).empty () != mNormalStack ->empty ()) {
88
- (*Problem <T, D>::mStack ).empty ();
89
- Problem <T, D>::println ();
86
+ StackAlgo <T, D>::mIndex ++;
87
+ if ((*StackAlgo <T, D>::mStack ).empty () != mNormalStack ->empty ()) {
88
+ (*StackAlgo <T, D>::mStack ).empty ();
89
+ StackAlgo <T, D>::println ();
90
90
std::cout << mNormalStack ->toString () << std::endl;
91
- (*Problem <T, D>::mStack ).empty ();
91
+ (*StackAlgo <T, D>::mStack ).empty ();
92
92
throw " One stack is empty and not the other" ;
93
93
}
94
- while ((!(Problem <T, D>::emptystack ())) && (popCondition (data))) {
95
- Data<T, D> elt = Problem <T, D>::pop ();
94
+ while ((!(StackAlgo <T, D>::emptystack ())) && (popCondition (data))) {
95
+ Data<T, D> elt = StackAlgo <T, D>::pop ();
96
96
Data<T, D> eltNormal = mNormalStack ->pop ();
97
97
popAction (elt);
98
98
bool bIndex = elt.mIndex == eltNormal.mIndex ;
99
99
bool bData = elt.mData == eltNormal.mData ;
100
100
if (!bIndex || !bData) {
101
- Problem <T, D>::println ();
102
- // std::cout << *Problem <T, D>::mContext << std::endl;
101
+ StackAlgo <T, D>::println ();
102
+ // std::cout << *StackAlgo <T, D>::mContext << std::endl;
103
103
std::cout << mNormalStack ->toString () << std::endl;
104
104
throw " The two elements popped are different" ;
105
105
}
106
106
}
107
107
if (pushCondition (data)) {
108
- Data<T, D> elt (Problem <T, D>::mIndex , data);
108
+ Data<T, D> elt (StackAlgo <T, D>::mIndex , data);
109
109
pushAction (elt);
110
- Problem <T, D>::push (elt);
110
+ StackAlgo <T, D>::push (elt);
111
111
mNormalStack ->push (elt);
112
112
}
113
- if (Problem <T, D>::mStack ->getBufferSize () > 0 ) {
113
+ if (StackAlgo <T, D>::mStack ->getBufferSize () > 0 ) {
114
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;
115
+ for (int k = 1 ; k <= StackAlgo <T, D>::mStack ->getBufferSize (); k++) {
116
+ if (StackAlgo <T, D>::mStack ->top (k).mIndex == mNormalStack ->top (k).mIndex ) {
117
+ StackAlgo <T, D>::println ();
118
+ // std::cout << *StackAlgo <T, D>::mContext << std::endl;
119
119
std::cout << mNormalStack ->toString () << std::endl;
120
120
throw " The two elements at the k = $(k) position are different" ;
121
121
}
@@ -129,14 +129,14 @@ template <class T, class D> void CompareStacks<T, D>::runCompare(int buffer) {
129
129
130
130
template <class T , class D > void CompareStacks<T, D>::readPush(int iter) {
131
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 ();
132
+ std::streampos position = StackAlgo <T, D>::mInput .tellg ();
133
+ StackAlgo <T, D>::mStack ->setPosition (position);
134
+ std::vector<std::string> line = StackAlgo <T, D>::readLine ();
135
135
D data = readInput (line);
136
- Problem <T, D>::mIndex ++;
137
- Data<T, D> elt (Problem <T, D>::mIndex , data);
136
+ StackAlgo <T, D>::mIndex ++;
137
+ Data<T, D> elt (StackAlgo <T, D>::mIndex , data);
138
138
pushAction (elt);
139
- Problem <T, D>::push (elt);
139
+ StackAlgo <T, D>::push (elt);
140
140
mNormalStack ->push (elt);
141
141
}
142
142
}
0 commit comments