Tutorial by Examples

Quicksort is a sorting algorithm that picks an element ("the pivot") and reorders the array forming two partitions such that all elements less than the pivot come before it and all elements greater come after. The algorithm is then applied recursively to the partitions until the list is so...
public class QuickSort { private static int Partition(int[] input, int low, int high) { var pivot = input[high]; var i = low - 1; for (var j = low; j <= high - 1; j++) { if (input[j] <= pivot) { i++; ...
quickSort :: Ord a => [a] -> [a] quickSort [] = [] quickSort (x:xs) = quickSort [ y | y <- xs, y <= x ] ++ [x] ++ quickSort [ z | z <- xs, z > x ]
public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] ar = new int[n]; for(int i=0; i<n; i++) ar[i] = sc.nextInt(); quickSort(ar, 0, ar.length-1); } public static void quickSort(...
def quicksort(arr): if len(arr) <= 1: return arr pivot = arr[len(arr) / 2] left = [x for x in arr if x < pivot] middle = [x for x in arr if x == pivot] right = [x for x in arr if x > pivot] return quicksort(left) + middle + quicksort(right) print qu...

Page 1 of 1