* QuickSort implementation. * This allows for a simple compare function for all the ADT. */
| 723 | * This allows for a simple compare function for all the ADT. |
| 724 | */ |
| 725 | static void QuickSort(void **left, void **right, dCompareFunc compare) |
| 726 | { |
| 727 | void **p = left, **q = right, **t = left; |
| 728 | |
| 729 | while (1) { |
| 730 | while (p != t && compare(*p, *t) < 0) |
| 731 | ++p; |
| 732 | while (q != t && compare(*q, *t) > 0) |
| 733 | --q; |
| 734 | if (p > q) |
| 735 | break; |
| 736 | if (p < q) { |
| 737 | void *tmp = *p; |
| 738 | *p = *q; |
| 739 | *q = tmp; |
| 740 | if (t == p) |
| 741 | t = q; |
| 742 | else if (t == q) |
| 743 | t = p; |
| 744 | } |
| 745 | if (++p > --q) |
| 746 | break; |
| 747 | } |
| 748 | |
| 749 | if (left < q) |
| 750 | QuickSort(left, q, compare); |
| 751 | if (p < right) |
| 752 | QuickSort(p, right, compare); |
| 753 | } |
| 754 | |
| 755 | /** |
| 756 | * Sort the list using a custom function |