'import' does not name a type; did you mean 'short'? import java.util.*;

import java.util.*;
public class Main {
public static void sort(int arr[],int low,int high){
if(low>=high)
return;
int mid=(low+high)/2;
int pivot=arr[mid];
int left=low;
int right=high;
while(left<=right){
while(arr[left]<pivot){
left++;
}
while(arr[right]>pivot){
right–;
}
if(left<=right){
int temp=arr[left];
arr[left]=arr[right];
arr[right]=temp;
}
}
sort(arr,low,right);
sort(arr,left,high);
}

public static void arrays(int arr[],int n){
    for(int i=0;i<n;i++){
       System.out.print(arr[i]+" "); 
    }}

public static void main(String args[]) {
	try{
	Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
    int arr[] =new int[n];
    System.out.println();
	for(int h=0;h<n;h++)
	arr[h]=sc.nextInt();
    Main ob = new Main(); 
    ob.sort(arr, 0, n-1);  
    System.out.println();
 arrays(arr,n); 
}catch(Exception e){System.out.println(e);}
 }

}

import java.util.*;
public class Main {
public static void sort(int arr[],int low,int high){
if(low>=high)
return;
int mid=(low+high)/2;
int pivot=arr[mid];
int left=low;
int right=high;
while(left<=right){
while(arr[left]<pivot){
left++;
}
while(arr[right]>pivot){
right–;
}
if(left<=right){
int temp=arr[left];
arr[left]=arr[right];
arr[right]=temp;
}
}
sort(arr,low,right);
sort(arr,left,high);
}

public static void arrays(int arr[],int n){
for(int i=0;i<n;i++){
System.out.print(arr[i]+" ");
}}

public static void main(String args[]) {
try{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int arr[] =new int[n];
System.out.println();
for(int h=0;h<n;h++)
arr[h]=sc.nextInt();
Main ob = new Main();
ob.sort(arr, 0, n-1);
System.out.println();
arrays(arr,n);
}catch(Exception e){System.out.println(e);}
}
}

Just a small typo at right–; Anyway it’s still giving TLE. Correct it out. It’s not giving no compile time errors now.

then how it will solve

I don’t see how this is quicksort. Where have you coded the partition logic , it doesn’t work as intended. Your pivot itself starts to move without first correctly placing all the other required elements. Correct your partition logic. You could take help from the article at GFG and if you face any issue understanding it, ask me.

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.