Created
June 25, 2011 20:37
-
-
Save mikebrock/1046873 to your computer and use it in GitHub Desktop.
Functional Quicksort in MVEL 2.1
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
/** | |
* Sample MVEL 2.1 Script | |
* "Functional QuickSort" | |
* by: Christopher Michael Brock, Inspired by: Dhanji Prasanna | |
*/ | |
def quicksort(list) { | |
list.size() <= 1 ? list : | |
(pivot = list[0]; (quicksort(($ in list if $ < pivot)) + pivot) | |
+ quicksort(($ in list if $ > pivot))) | |
} | |
// create a list to sort | |
list = [5,2,4,1,18,10,15,1,0]; | |
// sort it! | |
quicksort(list); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment