Optimise leftDefragmentation method

This commit is contained in:
manzerbredes 2015-05-03 09:25:28 +02:00
parent 98a8e2d520
commit afd4ba110f

View file

@ -137,18 +137,22 @@ std::vector<int> Grid::rightDefragment(std::vector<int> line){
}
std::vector<int> Grid::leftDefragment(std::vector<int> line){
for(int j=0; j<m_size-1;j++){
for(int i=m_size-1; i>0;i--){
int val1=line.at(i);
int val2=line.at(i-1);
if(val1 != 0 && val2 == 0){
line.at(i)=0;
line.at(i-1)=val1;
}
}
}
return line;
//for(int j=0; j<m_size-1;j++){
//for(int i=m_size-1; i>0;i--){
//int val1=line.at(i);
//int val2=line.at(i-1);
//if(val1 != 0 && val2 == 0){
//line.at(i)=0;
//line.at(i-1)=val1;
//}
//}
//}
std::vector<int> reversedLine= this->reverseLine(line);
return this->reverseLine(this->rightDefragment(reversedLine));
}
std::vector<int> Grid::rightMerge(std::vector<int> line){
for(int i=0; i< m_size-1;i++){