Skip to content

Instantly share code, notes, and snippets.

@jhyland87
Forked from edwardbadboy/awklib.awk
Created January 30, 2017 19:50
Show Gist options
  • Save jhyland87/469ca8d6ca7498f6d0ed35aedf0a1521 to your computer and use it in GitHub Desktop.
Save jhyland87/469ca8d6ca7498f6d0ed35aedf0a1521 to your computer and use it in GitHub Desktop.
useful awk functions
function qsort(A, left, right, i, last) {
if (left >= right)
return
last = left
for (i = left+1; i <= right; i++)
if (A[i] < A[left])
swap(A, ++last, i)
swap(A, left, last)
qsort(A, left, last-1)
qsort(A, last+1, right)
}
function swap(A, i, j, t) {
t = A[i]; A[i] = A[j]; A[j] = t
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment