While in Russia...

We can analyze the ``while'' version of the Russian Peasant's algorithm the same way.

int Russian(int a, int b)
//  implements Russian Peasant Algorithm
{
   int x = a, y = b, z = 0;
   while (x > 0)
   {
      if ( 1 == x % 2)
         z += y;
      y <<= 1;
      x >>= 1;
   }
   return z;        
}


next up previous
Next: Quicksort Pivot Up: EXAMPLES Previous: EXAMPLES