From c8d54ab6c1fe602a1be6a0075ea93d08aaccb7ef Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Wed, 10 Apr 2024 13:25:45 +0200 Subject: [PATCH] add comments to dual pivot quicksort --- lab2/zad4/src/main.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lab2/zad4/src/main.rs b/lab2/zad4/src/main.rs index c5c1505..0d27a41 100644 --- a/lab2/zad4/src/main.rs +++ b/lab2/zad4/src/main.rs @@ -41,7 +41,9 @@ fn dual_pivot_partition(list: &mut [u64], res: &mut SortResult) -> (usize, usize let q = list[list.len() - 1]; while k <= g { + // l > s if ((list.len() - 1) - g) > (l - 1) { + // list[k] >= q if compare(list[k], q, &mut comps) != LESS { while compare(list[g], q, &mut comps) == GREATER && k < g { g -= 1; @@ -52,14 +54,18 @@ fn dual_pivot_partition(list: &mut [u64], res: &mut SortResult) -> (usize, usize swap(list, k, l, &mut swaps); l += 1; } + // list[k] < p } else if compare(list[k], p, &mut comps) == LESS { swap(list, k, l, &mut swaps); l += 1; } + // l < s } else { + // list[k] < p if compare(list[k], p, &mut comps) == LESS { swap(list, k, l, &mut swaps); l += 1; + // list[k] >= q } else if compare(list[k], q, &mut comps) != LESS { while compare(list[g], q, &mut comps) == GREATER && k < g { g -= 1;