# quicksort.awk --- Quicksort algorithm, with user-supplied # comparison function # # Arnold Robbins, arnold@skeeve.com, Public Domain # January 2009 # quicksort --- C.A.R. Hoare's quicksort algorithm. See Wikipedia # or almost any algorithms or computer science text. # # Adapted from K&R-II, page 110 function quicksort(data, left, right, less_than, i, last) { if (left >= right) # do nothing if array contains fewer return # than two elements quicksort_swap(data, left, int((left + right) / 2)) last = left for (i = left + 1; i <= right; i++) if (@less_than(data[i], data[left])) quicksort_swap(data, ++last, i) quicksort_swap(data, left, last) quicksort(data, left, last - 1, less_than) quicksort(data, last + 1, right, less_than) } # quicksort_swap --- helper function for quicksort, should really be inline function quicksort_swap(data, i, j, temp) { temp = data[i] data[i] = data[j] data[j] = temp }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
assert.awk | File | 383 B | 0644 |
|
bits2str.awk | File | 334 B | 0644 |
|
cliff_rand.awk | File | 307 B | 0644 |
|
ctime.awk | File | 234 B | 0644 |
|
ftrans.awk | File | 315 B | 0644 |
|
getopt.awk | File | 2.15 KB | 0644 |
|
gettime.awk | File | 2.43 KB | 0644 |
|
group.awk | File | 1.72 KB | 0644 |
|
have_mpfr.awk | File | 221 B | 0644 |
|
inplace.awk | File | 1.95 KB | 0644 |
|
intdiv0.awk | File | 462 B | 0644 |
|
join.awk | File | 378 B | 0644 |
|
libintl.awk | File | 238 B | 0644 |
|
noassign.awk | File | 422 B | 0644 |
|
ord.awk | File | 937 B | 0644 |
|
passwd.awk | File | 1.17 KB | 0644 |
|
processarray.awk | File | 355 B | 0644 |
|
quicksort.awk | File | 1.01 KB | 0644 |
|
readable.awk | File | 489 B | 0644 |
|
readfile.awk | File | 267 B | 0644 |
|
rewind.awk | File | 404 B | 0644 |
|
round.awk | File | 661 B | 0644 |
|
shellquote.awk | File | 472 B | 0644 |
|
strtonum.awk | File | 1.42 KB | 0644 |
|
walkarray.awk | File | 214 B | 0644 |
|
zerofile.awk | File | 424 B | 0644 |
|