It turns out that in a collection of integers, when swapping two numbers, say a and b, I was doing the following:
temp = a;
a = b;
b = a;
Instead of the blatantly obvious:
temp = a;
a = b;
b = temp;
It is utterly unbelievable how such an error could have slipped my attention. Oh, well, us MVPs are also mere mortals after all.
1 comment:
if you don't want to use any temporaries.
a = a ^ b;
b = b ^ a;
a = a ^ b;
- basit
Post a Comment