From 6b23e614d9b47990ef6bf7344fd00c330014afde Mon Sep 17 00:00:00 2001 From: Michael Liendo Date: Sun, 12 Nov 2023 03:53:59 -0400 Subject: [PATCH] Refactored quicksort implementation to improve semantic --- src/quicksort.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/quicksort.rs b/src/quicksort.rs index 62fa62e..b7bb94c 100644 --- a/src/quicksort.rs +++ b/src/quicksort.rs @@ -29,9 +29,12 @@ where let mut greater_than_pivot: Vec = quicksort(&coll.iter().filter(|i| *i > pivot).cloned().collect()); + // Start building the result with the elements less than the pivot let mut result = less_than_pivot; + // Add the pivot to the result result.push(*pivot); + // Add the elements greater than the pivot to the result result.append(&mut greater_than_pivot); result