command! QsortDemo :call <SID>QsortDemo() func! s:QsortDemo() let list = [5, 2, 8, 9, 4, 1, 10, 3, 6, 7] echo list call <SID>Qsort(list, 0, 9) echo list endfunc func! s:Partition(list, p, q) let x = a:list[a:p] let i = a:p let j = i + 1 while j <= a:q if a:list[j] <= x let i = i + 1 call <SID>Exchange(a:list, i, j) endif let j = j + 1 endwhile call <SID>Exchange(a:list, a:p, i) return i endfunc func! s:Exchange(list, a, b) let tmp = a:list[a:a] let a:list[a:a] = a:list[a:b] let a:list[a:b] = tmp endfunc func! s:Qsort(list, p, r) if a:p < a:r let q = <SID>Partition(a:list, a:p, a:r) call <SID>Qsort(a:list, a:p, q - 1) call <SID>Qsort(a:list, q + 1, a:r) endif endfunc
:QsortDemo
[5, 2, 8, 9, 4, 1, 10, 3, 6, 7]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Ok!