4 ms·
Not to compete with your brilliant code on optimization, bu I have also written a swap routine that excels especially on numbers close to each other. I know sig
by orhano 3y ago
Not to compete with your brilliant code on optimization, bu I have also written a swap routine that excels especially on numbers close to each other. I know sign function result can be put into a variable, but computers nowadays are so fast...
Anyone feel free to use it.
static void swap(ref int a, ref int b)
{
int c = (b - a) ;
while (c != 0)
{
a += Math.Sign(c);
b -= Math.Sign(c);
c -= Math.Sign(c);
}
}