(base, count, size, compare)
| 172 | extern void free(); |
| 173 | |
| 174 | void |
| 175 | qsort(base, count, size, compare) |
| 176 | char *base; |
| 177 | int count; |
| 178 | REG int size; |
| 179 | int (*compare)(); |
| 180 | { |
| 181 | REG int i, cmp; |
| 182 | REG char *next, *prev, *tmp = 0; |
| 183 | char wrk_buf[512]; |
| 184 | |
| 185 | /* just use a shuffle sort (tradeoff between efficiency & simplicity) */ |
| 186 | /* [Optimal if already sorted; worst case when initially reversed.] */ |
| 187 | for (next = base, i = 1; i < count; i++) { |
| 188 | prev = next, next += size; /* increment front pointer */ |
| 189 | if ((cmp = (*compare)(next, prev)) < 0) { |
| 190 | /* found element out of order; move other(s) up then re-insert it |
| 191 | */ |
| 192 | if (!tmp) |
| 193 | tmp = size > (int) (sizeof wrk_buf) ? malloc(size) : wrk_buf; |
| 194 | memcpy(tmp, next, size); /* save smaller element */ |
| 195 | while (cmp < 0) { |
| 196 | memcpy(prev + size, prev, size); /* move larger elem. up */ |
| 197 | prev -= size; /* decrement back pointer */ |
| 198 | cmp = (prev >= base ? (*compare)(tmp, prev) : 0); |
| 199 | } |
| 200 | memcpy(prev + size, tmp, size); /* restore small element */ |
| 201 | } |
| 202 | } |
| 203 | if (tmp != 0 && tmp != wrk_buf) |
| 204 | free(tmp); |
| 205 | return; |
| 206 | } |
| 207 | #endif /*!SUPPRESS_QSORT*/ |
| 208 | |
| 209 | #endif /*VERYOLD_VMS*/ |
no outgoing calls
no test coverage detected