Quick Sort Java Implementation Code
import java.util.Arrays; class QuickSort { public static void main(String[] args) { int[] inputArray = new int[] { 89,5 ,27, 18, 9, 3, 27, 54, 21, 108 }; QuickSort uc = new QuickSort(); uc.quickSort(inputArray, 0, inputArray.length - 1); System.out.println(Arrays.toString(inputArray)); } private void quickSort(int[] array, int start, int end) { if (start < end) { int p = partition(array, start, end); quickSort(array, start, p - 1); quickSort(array, p + 1, end); } } private int partition(int[] array, int start, int end) { int pivot = array[end]; int i = start - 1; int j = start; while(j <= end-1) { if (array[j] <= pivot) { ++i; int iVal = array[i]; int jVal = array[j]; array[j] = iVal; array[i] = jVal; } j++; } int iVal = array[i+1]; array[end] = iVal; array[i+1] = pivot; return i+1; } }
Output:
[3, 5, 9, 18, 21, 27, 27, 54, 89, 108]
La weekly I really like reading through a post that can make men and women think. Also, thank you for allowing me to comment!
Real Estate This is really interesting, You’re a very skilled blogger. I’ve joined your feed and look forward to seeking more of your magnificent post. Also, I’ve shared your site in my social networks!
Techno rozen naturally like your web site however you need to take a look at the spelling on several of your posts. A number of them are rife with spelling problems and I find it very bothersome to tell the truth on the other hand I will surely come again again.
Hi, I’m Jack. Your website has become my go-to destination for expert advice and knowledge. Keep up the fantastic work!
Simply Sseven naturally like your web site however you need to take a look at the spelling on several of your posts. A number of them are rife with spelling problems and I find it very bothersome to tell the truth on the other hand I will surely come again again.
Family Dollar I’m often to blogging and i really appreciate your content. The article has actually peaks my interest. I’m going to bookmark your web site and maintain checking for brand spanking new information.
Henof Nice post. I learn something totally new and challenging on websites
Insanont This was beautiful Admin. Thank you for your reflections.
Fran Candelera I appreciate you sharing this blog post. Thanks Again. Cool.
Baddiehub Nice post. I learn something totally new and challenging on websites
Blue Techker I just like the helpful information you provide in your articles