Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

XOR bubble sort

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;
}

Name: >>3 2010-05-22 14:33

>>6
Sure can, there is no reasonable usage of a bubble sort, because virtually EVERY sorting algorithm is better than it. I say virtually every, only because we have stupid stuff like bogosort, which is meant as a joke. The only possible reason for the possible reason for the continued existence of the Bubble sort is as a teaching mechanism, and I would suggest that even then it shouldn't be taught.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List