- #1
needOfHelpCMath
- 72
- 0
I have never done Java but my professor says it is similar to c++. I am trying to convert quicksort in java and covert it to c++.
I don't know if this is correct or not. Here is the code my professor gave us.
I don't know if this is correct or not. Here is the code my professor gave us.
Code:
.....Java......
public static void quicksort(char[], int left, int right)
{
int i, j;
i - left; j - right;
x = items[(left+right) / 2];
do
{
while([items[i] < x) && (i <right)] i++;
while[(x < items[j]) && (i > left)] j--;
if (i <= j) {
y = items[i];
items[i] = items[j];
items[j] = y;
i++; j--; }
}
while(i<=j);
if (left < j) quicksort(items, left, j);
if (i < right)quicksort(items,i,right);
}
Code:
......C++......
void QuickSort(int[] nums, int left, int right) {
int i, j,;
int x, y;
i - left;
j-right;
x = nums[(left+right)/2];
while(nums[i] < x && i < right) {
++i;
while(x < num[j] && j > left) {
j--;
if(i <= j) {
y = nums[i];
nums[i] = nums[j];
nums[j] = y;
i++; j--;
}
}
}
}
while(i <= j) {
if(left < j) {
QuickSort(nums, left);
}
if(i < right) {
QuickSort(nums,i,right);
}
}