Skip to content

Instantly share code, notes, and snippets.

@vkorobkov
Created December 29, 2016 06:06
Show Gist options
  • Save vkorobkov/27d94cd45c69f1032d7fcb7fe0540dc9 to your computer and use it in GitHub Desktop.
Save vkorobkov/27d94cd45c69f1032d7fcb7fe0540dc9 to your computer and use it in GitHub Desktop.
Easy quick sort function writtern in Groovy
def quickSort(List list, beg = 0, end = list.size() - 1) {
if (list.size() < 2) {
return
}
def beg0 = beg
def end0 = end
def marker = list[beg]
while(true) {
while (list[beg] < marker) beg++
while (list[end] > marker) end--
if (beg < end) {
def t = list[beg]
list[beg] = list[end]
list[end] = t
beg++
end--
}
else {
break
}
}
if (beg0 < end) quickSort(list, beg0, end)
if (end + 1 < end0) quickSort(list, end + 1, end0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment