can somebody tell me how to rotate a c++ array x times to the left or x times to the right?????
please i really need to know
thanks
Printable View
can somebody tell me how to rotate a c++ array x times to the left or x times to the right?????
please i really need to know
thanks
What exactly do you mean by "rotate". Please be more specific.
Cheers,
cgkanchi
Sounds like he means in the graphical sense.
The easiest way to code it would probably be to loop through the array, and turn all of the values into an ordered list... Then read the list back into the array with different loop conditions... Just some psuedocode stuff here...
There are probably some off-by-one errors in there, but I'm lazy.Code://array is called Array[Row][Column]...
list.clearList();
// read it
for(int i=0;i<Row;i++)
{
for(int j=0;j<Column;j++)
{
list.add(Array[i][j];
}
}
//Write it -- Rotation to the right
for(int i=(Columns-1);i>0;i--)
{
for(int j=0;j<Rows;j++)
{
Array[j][i] = list.getNext();
}
}