Name: Anonymous 2010-10-24 4:13
There's an array of values from 1 to n. It isn't sorted. We have to sort it, but there are only to ways to move: third element to beginning or last element to beginning. How to do that ?
check array n > 2
while ( !sorted )
{
if ( rand() & 1 )
third_to_start();
if ( rand() & 1 )
last_to_start();
}