QuickSort | Algo not Working Correctly

My algorithm is not working.
Input -> int[] array = {40,20,90,30,70};
Output -> {20,40,70,30,90};

Array is not correctly sorted.

I have soend lot of hours but still not able to ubdertand where is the problem.

public static void quickSort(int[] array, int low, int high){

	if(low >= high) {
		return;
	}
					
	int left = low;
	int right = high;
	int pivotPoint = (low + high)/2;
	
	while(left<=right){		
		
		while(array[left]<array[pivotPoint]){
			++left;
		}
	
               
        while(array[right]>array[pivotPoint]){
			--right;
		}
		
		if(left<=right){
			int temp = array[left];
			array[left] = array[right];
			array[right] = temp;
		}
		
		++left;
		--right;
		
	}
	
	
	quickSort(array,low,right);
	quickSort(array,left,high);
	
}

Hey @connectrajanjain There is a very sligh mistake that you have made when you are decrementing and incrementing left and right in the main while loop it should be within if statement look for comments in the code below :
public static void quickSort(int[] array, int low, int high){

	if(low >= high) {
		return;
	}
					
	int left = low;
	int right = high;
	int pivotPoint = (low + high)/2;
	
	while(left<=right){		
		
		while(array[left]<array[pivotPoint]){
			++left;
		}
	
               
        while(array[right]>array[pivotPoint]){
			--right;
		}
		
		if(left<=right){
			int temp = array[left];
			array[left] = array[right];
			array[right] = temp;
                 //Changes in left and right are made here
                        ++left;
		        --right;
		}

		//Initially your changes were here
	
		
	}
	
	
	quickSort(array,low,right);
	quickSort(array,left,high);
	
}

Thank you for pointing it and i will rerun the program but can you explain why it should be inside if block ??? Why the program is not working as expected when ( increment and decrement ) are outside.

Hey @connectrajanjain It is bcoz if the case is for left > right then also left and will be incremented and decremented and after which when you make calls by using left and right it will be different.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Make sense. Thank for your response.