I am new to C ++ and I am trying to do one thing that is easy in python using slice lists, but I cannot find an easy way to do this in C ++.
I need to reorder the array to start with this element, for example: int array [] = {1,2,3,4,5}; reordered array to start in element 3: {3,4,5,1,2}
so I found it, but it seems to be a bit overkill:
void Graph::reorder(int x, MIntArray ¤tArray) { MIntArray reorderedIndices; int index; for (unsigned int i=0; i<currentArray.length();i++){if(currentArray[i]==x){index=i;}} // get the index for (unsigned int i=index; i<currentArray.length();i++){reorderedIndices.append(currentArray[i]);} // zero to index for (unsigned int i=0; i<index;i++){reorderedIndices.append(currentArray[i]);} // index to last for (unsigned int i=0; i<currentArray.length();i++){currentArray.set(reorderedIndices[i],i);} // transfer }
Any help would be greatly appreciated!
thanks
Louis
source share