Skip to content

Commit 50b6a79

Browse files
committed
Normal Stack is functionnal. Problem interface too (with associated README.md file)
1 parent ef7fb7e commit 50b6a79

File tree

4 files changed

+8
-22
lines changed

4 files changed

+8
-22
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# CompressedStacks.cpp
22
```cpp
33
// Class for test instance
4-
// T is the type of the context and D is the type of the input data. Please change it on 1st and 3rd lines.
4+
// T is the type of the context and D is the type of the input data. Please change it on 1st, 3rd, 4th, 18th, and 25th lines.
55
class Instance: public Problem<T,D>{
66
public:
77
Instance(std::string filePath, int size):Problem<T,D>(filePath, size){}
8+
Instance(std::string filePath, int size, int space):Problem<T,D>(filePath, size, space){}
89
private:
910
// Functions to implement according to the problem and input
1011
int mReadInput(){

include/normalStack.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ template <class D>
5353
template <class D>
5454
void NormalStack<D>::push(Data<D> elt)
5555
{
56-
std::cout << "Ultra Push! : data = " << (elt.getData()) << std::endl;
5756
mDatas.push_back(elt);
58-
std::cout << "Size of the stack : " << (mDatas.size()) << std::endl;
59-
println();
6057
}
6158

6259
template <class D>

include/problem.hpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Problem<T,D>::Problem(std::string fileName, int size)
6969
mInput.open(fileName, std::ifstream::in);
7070
mOutput = nullptr;
7171

72-
mContext = nullptr;
72+
mContext = new T();
7373
mIndex = 0;
7474

7575
mStack = new NormalStack<T> (size);
@@ -117,13 +117,10 @@ std::vector<std::string> Problem<T,D>::readLine()
117117
std::vector<std::string> line;
118118
size_t pos=std::string::npos;
119119
getline(mInput,str);
120-
std::cout << "Debug 4 : " << str << std::endl;
121120
while (true){
122121
pos=str.find_first_of(",");
123122
line.push_back(str.substr(0,pos));
124-
std::cout << "Debug 4.2 : " << str << " and pos = " << pos << std::endl;
125123
str.erase(0,pos+1);
126-
std::cout << "Debug 4.1 : " << str << " and pos = " << pos << std::endl;
127124
if (pos=std::string::npos){
128125
line.push_back(str.substr(0,pos));
129126
str.erase(0,pos);
@@ -139,13 +136,10 @@ template <class T, class D>
139136
void Problem<T,D>::run() {
140137
initStack();
141138
while ((mInput.good())) {
142-
std::cout << "Debug 1" << std::endl;
143139
std::vector<std::string> line = readLine();
144140
if ( (line.front()== "-1") || (line.front()=="") ) {
145141
break;
146142
}
147-
std::cout << "Debug 2 : size = " << line.size() << std::endl;
148-
std::cout << "Context = " << (line.back()) << std::endl;
149143
D data = readInput(line);
150144
mIndex++; // Might have to move
151145
while ( (emptystack()) && (popCondition(data)) ) {
@@ -156,7 +150,6 @@ void Problem<T,D>::run() {
156150
Data<D> elt (mIndex,data);
157151
pushAction(elt);
158152
push(elt);
159-
println();
160153
}
161154
}
162155
}
@@ -189,10 +182,10 @@ void Problem<T,D>::setOutput(std::string fileName){
189182

190183
template <class T, class D>
191184
void Problem<T,D>::setContext(T context){
192-
std::cout << "setContext, T = " << context << std::endl;
193-
mContext = &context;
194-
std::cout << "setContext, *mContext = " << (*mContext) << std::endl;
195-
std::cout << "setContext, *mContext = " << getContext() << std::endl;
185+
// std::cout << "setContext, T = " << context << std::endl;
186+
*mContext = context;
187+
// std::cout << "setContext, *mContext = " << (*mContext) << std::endl;
188+
// std::cout << "setContext, *mContext = " << getContext() << std::endl;
196189
}
197190

198191
/** Getters **/

src/main.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,11 @@ class Instance: public Problem<int,int>{
7474

7575
}
7676
void initStack(){
77+
setContext(10);
7778
std::vector<std::string> line = readLine(); // Temporary measure to get rid of the first line
78-
setContext(0);
79-
std::cout << "Debug 3 : size = " << line.size() << std::endl;
80-
std::cout << "Implement mInitStack for your instance" << std::endl;
8179
}
8280
bool popCondition(int data){
8381
if (getContext() > 0) {
84-
std::cout << "Pop! : Context = " << (getContext()) << std::endl;
8582
return true;
8683
}
8784
return false;
@@ -91,10 +88,8 @@ class Instance: public Problem<int,int>{
9188
}
9289
bool pushCondition(int data){
9390
if (data > 0) {
94-
std::cout << "Push!" << std::endl;
9591
return true;
9692
}
97-
std::cout << "No Push!" << std::endl;
9893
return false;
9994
}
10095
void pushAction(Data<int> elt){

0 commit comments

Comments
 (0)