Created
August 9, 2023 11:00
-
-
Save FCO/a8d4bf9710faf7dd0673c56d790bb5de to your computer and use it in GitHub Desktop.
Quicksort using classify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
multi quicksort([]) { Empty } | |
multi quicksort([$pivot, *@rest]) { | |
my %list{Order} is default([]) = @rest.classify: * cmp $pivot; | |
[ |quicksort(%list{Less}), $pivot, |%list{Same}, |quicksort(%list{More}) ] | |
} | |
say quicksort [7, 2, 1, 8, 1, 9, 3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment