QSORT - sort an array of things.
Alternate Entry Name: .QSORT
Usage:
B:
qsort(vec, n, bytes [, compare])
/* C users use the C "qsort" */
Where:
- vec
- is a pointer to the array to be sorted.
- n
- is the actual number of items to be sorted.
- bytes
- is the size of each item in bytes.
- compare
- is an optional function to compare two elements of
"vec". It will be called with "compare(p,
q, s)", where:
- p
- is a byte pointer (upper 20 bits) to an element.
- q
- is a byte pointer to another element.
- s
- is a copy of the "bytes" argument to
QSORT.
- "compare" should return a negative, zero or
positive value depending on whether the element pointed
to by "p" is less than, equal to or greater
than the element pointed to by "q". If
"compare" is omitted, QSORT will do a logical
byte string compare between elements.
Description:
QSORT is used to sort an array of byte vectors. The array
elements can be any number of bytes long, and thus may lie on any
byte boundary. Because of this, "compare" is passed C
type byte pointers, so it may be necessary to shift these down by
18 bits to use them as B pointers.
Currently, QSORT uses the "Shell sort" algorithm.
See Also:
- expl b lib shells
- for a routine that just sorts word quantities.
Copyright © 1996, Thinkage Ltd.