Date: 07/05/06 (Algorithms) Keywords: no keywords
People used to use a temp variable to swap two variables, here is a trick that doesn't use an additional register:#define SWAP(a,b) a^=b^=a^=bBut we have a problem, that method doesn't work with floating point variables... ok, every problem has a solution, try it:#define SWAP2(a,b) a=a+b;b=a-b;a=a-bHave a good coding!
Source: http://community.livejournal.com/algorithms/80373.html