http://high-auto-insurance-quotes.blogspot.com/

External links - Jquery You See how much you can save on reliable, affordable car insurance. Get your free quote online or over the phone and compare auto insurance rates in minutes?

All you need to try it here you wont be sorry ! go try it GUMGUM :) Auto Insurance Quotes Compare about Auto Insurance Quotes Compare

http://austindwi-defense.blogspot.com

External links - JqueryThe Dunham Law Firm handles Texas DWI (Driving While Intoxicated), DUI (Driving Under the Influence) and BWI (Boating While Intoxicated) cases in and around Travis County, Texas. Having Texas Board Certified Criminal Law Specialists* and former prosecutors handling your DWI defense case in Austin can make the difference between winning, going to jail or doing DWI probation. You will find our law firm to be very knowledgeable about Texas DWI Laws and drunk driving penalties and information.

DWI (Driving While Intoxicated) ? GO Driving While Intoxicated :)

Hide Blogger Navbar in New Blogger Blogspot !

External links - Jquery Want to get rid of the blogger toolbar in new blogger that just came out of beta ? If you have shifted your blogspot blog from old blogger to the new blogger beta, you may have noticed that the previous CSS code to remove the blogger navbar will no longer be effective. That's because Google now uses different CSS tags to display the blogger bar. [#navbar-iframe instead of #b-navbar] If you want to hide the navbar in your blogger blog, here's what you should do ! (these instructions refer to the "new" Blogger layouts templates) GO GET IT GUMGUM:)

Super Sexy Bookmarks Widget for Blogger !

Thumbnail image that says sleek button using photoshop that links to a Photoshop tutoril. Looking for professional Social Bookmark Buttons for your blog ! me too :) however, while i was searching the net too, I came across a post by Naeemnur, that had instructions for Blogger (BlogSpot.com) based blogs which was really good.If you have a blog on blogger you can definitely give this a try.

Its very attractive social bookmarking widget ! it can help you to let your visitors bookmark your page effectively .

for instructions about the use of this SEXY Social bookmarking widget ! you can go here and get it GUMGUM:)

Saturday, August 6, 2011

Weird XOR swap problem (zeroing out data) | c++ - Weird XOR swap problem (zeroing out data)

Weird XOR swap problem (zeroing out data) | c++ - Weird XOR swap problem (zeroing out data)

void swap(int& a, int& b) {
    if (&a == &b) // added this check to ensure the same address is not passed in
        return;

    a ^= b;
    b ^= a;
    a ^= b;
}

I am implementing quicksort for fun in C++, and I am using integers for dummy data. I had been using the XOR swapping algorithm to swap two values in place, but I noticed my sort was screwing up. I changed my swapping algorithm and it worked. I added some debugging statements, and found that the XOR swap was doing something weird.
I printed the data before and after I swapped it, and this is what it printed:
...

swapping -5, -3
swapped  -3, -5

swapping -5, -5
swapped  0, 0     <---- What?

swapping -2, -4
swapped  -4, -2
...
Here is my code:
// this might not be that great or even work as intended but it doesn't really matter for this problem
int av3index(int a[], int indx1, int indx2, int indx3) {
    if (a[indx3] <= max(a[indx1], a[indx2]) && a[indx3] >= min(a[indx1], a[indx2]))
        return indx3;

    if (a[indx2] <= max(a[indx1], a[indx3]) && a[indx2] >= min(a[indx1], a[indx3]))
        return indx2;

    if (a[indx1] <= max(a[indx2], a[indx3]) && a[indx1] >= min(a[indx2], a[indx3]))
        return indx1;
}
void swap(int& a, int& b) {
    /*
    This works
    int tmp = b;
    b = a;
    a = tmp;*/

    cout << "swapping " << a << ", " << b << endl;

    a ^= b;
    b ^= a;
    a ^= b;

    cout << "swapped  " << a << ", " << b << endl << endl;
}
void zqsort(int a[], int len) {
    if (len <= 1)
        return;

    int pivot = av3index(a, 0, len / 2, len - 1);

    swap(a[pivot], a[0]);

    int i = 1, j = len - 1;

    while (i <= j) {
        if (a[i] > a[0]) {
            while (i <= j && a[j] > a[0])
                --j;

            if (i <= j)
                swap(a[i], a[j]);
        }

        ++i;
    }

    swap(a[0], a[j]);

    zqsort(a, len / 2);
    zqsort(a + len / 2, len - len / 2);
}
int main() {
    int values[] = {5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5};

    int len = sizeof(values) / sizeof(int);

    int* arr = new int[len];

    for (int i = 0; i < len; ++i)
        arr[i] = values[i];

    zqsort(arr, len);

    cout << "sorted array:" << endl;
    for (int i = 0; i < len; ++i)
        cout << arr[i] << endl;

    cin.get();
}
Read More

0 comments:

Post a Comment | Feed

Post a Comment



 

FAJAR MENYINGSING Copyright © 2011 REDHAT Dashboard Designed by SAER