Name: Anonymous 2010-05-22 13:14
Is there any useful application of a xor bubble sort as opposed to having spare temp variable?
#include <iostream>
using namespace std;
int main()
{
int x[5]={1, 5, 2, 4, 3};
for (int c1=0; c1<5; c1++) {
cout<<x[c1]<<endl;
}
cout<<endl;
for (int c1=0; c1<6; c1++) {
for (int c2=c1+1; c2<6; c2++) {
if (x[c1]>x[c2]) {
x[c1]=x[c1]^x[c2];
x[c2]=x[c1]^x[c2];
x[c1]=x[c1]^x[c2];
}
}
}
for (int c1=0; c1<5; c1++) {
cout<<x[c1]<<endl;
}
return 0;
}