Question

Can I have a quick sort program -java code- , I need really good one please...

Can I have a quick sort program -java code- , I need really good one please ??
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;
import java.lang.*;
import java.io.*;
class Quick_Sort {
  
   private int arr[];
   private int len;
   public void sort(int[] inputArr)
   {
       if(inputArr==null||inputArr.length==0)
           return;
       this.arr=inputArr;
       len=inputArr.length;
       quickSort(0,len - 1);
   }
   private void quickSort(int lIndex,int HIndex) {
       int i=lIndex;
       int j=HIndex;
       int pivot=arr[lIndex+(HIndex-lIndex)/2];
       while (i<=j){
           while(arr[i]<pivot) {
               i++;
           }
           while(arr[j]>pivot) {
               j--;
           }
           if(i<=j){
               swap(i,j);
               i++;
               j--;
           }
       }
       if (lIndex<j)
           quickSort(lIndex,j);
       if (i<HIndex)
           quickSort(i,HIndex);
   }
   private void swap(int i,int j) {
       int temp=arr[i];
       arr[i]=arr[j];
       arr[j]=temp;
   }
   public static void main(String a[]){  
       Quick_Sort sorter=new Quick_Sort();
       int n;
       System.out.println("Enter the size of the array :");
       Scanner sc=new Scanner(System.in);
       n=sc.nextInt();
       int []input = new int[n];
       for(int i=0;i<n;i++)
       {
           input[i]=sc.nextInt();
       }
   sorter.sort(input);
   for(int j=0;j<input.length;j++){
       System.out.print(input[j]);
       System.out.print(" ");
   }
   }
}

Add a comment
Know the answer?
Add Answer to:
Can I have a quick sort program -java code- , I need really good one please...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT