Optimise leftDefragmentation method
This commit is contained in:
parent
98a8e2d520
commit
afd4ba110f
1 changed files with 15 additions and 11 deletions
|
@ -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++){
|
||||
|
|
Loading…
Add table
Reference in a new issue