Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - import std.stdio, std.algorithm;
 - void quickSort(ref int[] arr) {
 - if (arr.length == 1) return;
 - int wall = 0;
 - int pivot = arr[$-1];
 - foreach (a; 1..arr.length-1) {
 - if (arr[a] <= pivot) {
 - swap(arr[wall], arr[a]);
 - wall++;
 - }
 - }
 - swap(arr[wall+1], arr[$-1]);
 - quickSort(arr[0..wall]);
 - quickSort(arr[wall+1..$]);
 - }
 - void main() {
 - int[] test = [6, 5, 1, 3, 8, 4, 7, 9, 2];
 - quickSort(test);
 - writeln(test);
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment