On 6/25/06, Thomas.Chang <[EMAIL PROTECTED]> wrote:
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;
} // <potentialBug> need an increment/decrement on swap </potentialBug>
}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 algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---
- [algogeeks] Can anyone point out the mistakes ... Thomas.Chang
- [algogeeks] Re: Can anyone point out the ... Nat (Padmanabhan Natarajan)
- [algogeeks] Re: Can anyone point out ... Thomas.Chang
- [algogeeks] Re: Can anyone point out the ... adak
- [algogeeks] Re: Can anyone point out ... Thomas.Chang