Following is a qsort() program, I checked it carefully severally times
and tested with a lot of cases without finding any error. But when I
submit the program using it to online judge, it always "wrong answer",
if I substitute it with the standard qsort() of c library, it will
pass.
I post it here wishing someone can point out my mistakes. It's really
frustrating having problem with such basic, simple algorithms.

-----------------------------------------------------------------------------------
int sticks[100];
void sort(int left,int right){
        int pivot, i, j;
        int temp;
        if(left<right){
                i=left; j=right+1;
                pivot = sticks[left];
                do{
                        do i++;
                        while (i<=right && sticks[i] < pivot );
                        do j--;
                        while (j>=left && sticks[j] > pivot);
                        if(i<j && i<=right && j>=left) {
                                temp = sticks[i];
                                sticks[i] = sticks[j];
                                sticks[j] = temp;
                        }
                }while(i<j);
                if(j>left){
                        temp = sticks[left];
                        sticks[left] = sticks[j];
                        sticks[j] = temp;
                }
                if(left<j) sort(left,j-1);
                if(j<right && left<=j) sort(j+1, right);
        }
}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to