Rev 2071 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2071 | Rev 2745 | ||
---|---|---|---|
Line 94... | Line 94... | ||
94 | * |
94 | * |
95 | */ |
95 | */ |
96 | void _qsort(void * data, count_t n, size_t e_size, int (* cmp) (void * a, void * b), void *tmp, void *pivot) |
96 | void _qsort(void * data, count_t n, size_t e_size, int (* cmp) (void * a, void * b), void *tmp, void *pivot) |
97 | { |
97 | { |
98 | if (n > 4) { |
98 | if (n > 4) { |
99 | int i = 0, j = n - 1; |
99 | unsigned int i = 0, j = n - 1; |
100 | 100 | ||
101 | memcpy(pivot, data, e_size); |
101 | memcpy(pivot, data, e_size); |
102 | 102 | ||
103 | while (1) { |
103 | while (1) { |
104 | while ((cmp(data + i * e_size, pivot) < 0) && i < n) i++; |
104 | while ((cmp(data + i * e_size, pivot) < 0) && (i < n)) |
- | 105 | i++; |
|
105 | while ((cmp(data + j * e_size, pivot) >=0) && j > 0) j--; |
106 | while ((cmp(data + j * e_size, pivot) >= 0) && (j > 0)) |
- | 107 | j--; |
|
- | 108 | ||
106 | if (i<j) { |
109 | if (i < j) { |
107 | memcpy(tmp, data + i * e_size, e_size); |
110 | memcpy(tmp, data + i * e_size, e_size); |
108 | memcpy(data + i * e_size, data + j * e_size, e_size); |
111 | memcpy(data + i * e_size, data + j * e_size, e_size); |
109 | memcpy(data + j * e_size, tmp, e_size); |
112 | memcpy(data + j * e_size, tmp, e_size); |
110 | } else { |
113 | } else { |
111 | break; |
114 | break; |