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: >>2 2010-05-22 14:20

>>6
What >>4 means is that bubble sort is an inefficient sort whose only redeeming quality is its ease of implementation. qsort, heap sort, shell sort and so on, perform much better than bubble sort.

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