diff --git a/C++ProjectTemplate b/C++ProjectTemplate index 1f9c1a3..f2683e0 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/main.cpp b/main.cpp index e68a09d..8779d4f 100644 --- a/main.cpp +++ b/main.cpp @@ -5,7 +5,7 @@ using namespace olc; struct Data{ - int value; //Number. + long value; //Number. int position; //Current position in the list. }; @@ -19,52 +19,72 @@ int main() std::getline(file,line); //std::cout<0){ - Data*data=new Data{std::atoi(line.c_str()),(int)originalSet.size()}; + Data*data=new Data{std::atoi(line.c_str())*811589153l,(int)originalSet.size()}; originalSet.push_back(data); newSet.push_back(data); } } - for (int i=0;iposition; - Data*temp=newSet[pos]; - int shift=val->value; - while (shift!=0){ - if (shift>0){ - //Move it to the right of the list. - int newPos=(pos+1)%newSet.size(); - /*std::cout<<" Swap "<value<<" ["<position<<"]"; - std::cout<<" with "<value<<" ["<position<<"]"<position=newPos; - newSet[pos]->position=pos; - shift--; - pos=newPos; - } else { - //Move it to the left of the list. - int newPos=pos-1; - if (newPos<0){ - newPos=newSet.size()-1; - } - /*std::cout<<" Swap "<value<<" ["<position<<"]"; - std::cout<<" with "<value<<" ["<position<<"]";*/ - newSet[pos]=newSet[newPos]; - newSet[newPos]=temp; - newSet[newPos]->position=newPos; - newSet[pos]->position=pos; - shift++; - pos=newPos; + std::cout<value<<" ["<position<<"]"; } + std::cout<position; + Data*temp=newSet[pos]; + long shift=(val->value)%(long)(originalSet.size()-1l); + std::cout<<"Shift value is "<0){ + //Move it to the right of the list. + int newPos=(pos+1)%newSet.size(); + /*std::cout<<" Swap "<value<<" ["<position<<"]"; + std::cout<<" with "<value<<" ["<position<<"]"<position=newPos; + newSet[pos]->position=pos; + shift--; + pos=newPos; + } else { + //Move it to the left of the list. + int newPos=pos-1; + if (newPos<0){ + newPos=newSet.size()-1; + } + /*std::cout<<" Swap "<value<<" ["<position<<"]"; + std::cout<<" with "<value<<" ["<position<<"]";*/ + newSet[pos]=newSet[newPos]; + newSet[newPos]=temp; + newSet[newPos]->position=newPos; + newSet[pos]->position=pos; + shift++; + pos=newPos; + } + } + /*std::cout<value<<" ["<position<<"]"; + } + std::cout<value<<" ["<position<<"]"; } - std::cout<value<value<value+newSet[offset2]->value+newSet[offset3]->value; + long sum=newSet[offset]->value+newSet[offset2]->value+newSet[offset3]->value; std::cout<<"Sum: "<