GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Java/QuickSort.java at main · Eggy115/Java Expand file tree/ Copy pathQuickSort.javaMore file actions 35 lines (32 loc) · 1.05 KB / Copy pathQuickSort.javaFile metadata and controls35 lines (32 loc) · 1.05 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 import java.util.Arrays; public class QuickSort { public static void main(String[] args) { int[] arr = { 38, 27, 43, 3, 9, 82, 10 }; System.out.println("Unsorted array: " + Arrays.toString(arr)); quickSort(arr, 0, arr.length - 1); System.out.println("Sorted array: " + Arrays.toString(arr)); } public static void quickSort(int[] arr, int left, int right) { if (left < right) { int pivotIndex = partition(arr, left, right); quickSort(arr, left, pivotIndex - 1); quickSort(arr, pivotIndex + 1, right); } } public static int partition(int[] arr, int left, int right) { int pivot = arr[right]; int i = left - 1; for (int j = left; j < right; j++) { if (arr[j] < pivot) { i++; int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } int temp = arr[i+1]; arr[i+1] = arr[right]; arr[right] = temp; return i+1; } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |