> https://www.codechef.com/problems/TSORT
> Test cases give expected output.
> I am getting the wrong answer in codechef.
The example on the problem page suggests you should be removing duplicates.
> return 0;
You may as well return void, because no other call captures the return result, and no return result is ever used.
> int arr[t];
This isn't valid C++.
Even if it was, given t is upto 10^6, it's likely to blow the stack for larger values of t.
Use int *arr = new int[t]; or better, a std::vector.
if(arr[i]>=pivot && arr[j]<=pivot)
¿what do you want to do with the `pivot' elements? ¿should they be on the left partition, the right partition or doesn't matter?
quicksort(arr,low,mid);
that's wrong, the partition doesn't end on `mid'
for example
{6, 7, 8, 1, 2, 3, 4, 5, 9}
mid is 4, pivot is arr[4] = 2
after the partition you may have
{1, 2, 9, 8, 7, 6, 5, 4, 3}
and you part on position 4 so the recursive calls have
{1, 2, 9, 8, 7}
{6, 5, 4, 3}
now you may never move 9 to the last position.
change the initial array then
after partition the left part should be lesser than the pivot and the right part greater
my point is that when you launch the recursive call you take more than you should (in the example, it should have been divided {1, 2} {9, 8, 7, 6, 5, 4, 3})
also
1 2 3 4 5 6
if(arr[i]>=pivot && arr[j]<=pivot){
//...
}
else{ //here you may have arr[i]>pivot
i++; //but you leave it on the left
}