Skip to content

Instantly share code, notes, and snippets.

@mikebrock
Created June 25, 2011 20:37
Show Gist options
  • Save mikebrock/1046873 to your computer and use it in GitHub Desktop.
Save mikebrock/1046873 to your computer and use it in GitHub Desktop.
Functional Quicksort in MVEL 2.1
/**
* 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