Add _sort_p algorithm

This commit is contained in:
Patrick Pelissier committed 2017-05-22 18:22:11 +02:00
1 parent b12701c381
commit f14e5222ad
2 files changed
+21 -1

No files matched your search

+19
View File
@@ -218,6 +218,25 @@
*max_p = max; \
} \
\
static inline bool M_C(name, _sort_p)(container_t l) \
{ \
it_t it1; \
it_t it2; \
M_GET_IT_FIRST cont_oplist (it1, l); \
M_GET_IT_SET cont_oplist (it2, it1); \
M_GET_IT_NEXT cont_oplist (it2); \
while (!M_GET_IT_END_P cont_oplist (it2)) { \
const type_t *ref1 = M_GET_IT_CREF cont_oplist (it1); \
const type_t *ref2 = M_GET_IT_CREF cont_oplist (it2); \
if (M_GET_CMP type_oplist (*ref1, *ref2) > 0) { \
return false; \
} \
M_GET_IT_SET cont_oplist (it1, it2); \
M_GET_IT_NEXT cont_oplist (it2); \
} \
return true; \
} \
\
/* Sort can be generated from 3 algorithms: */ \
/* - a specialized version defined by the container */ \
/* - an insertion sort (need 'previous' method) */ \
+2 -1
View File
@@ -54,8 +54,9 @@ static void test_list(void)
for(int i = -100; i < 100; i+=2)
list_int_push_back (l, i);
assert (!algo_list_sort_p(l));
algo_list_sort(l);
// TODO: assert (algo_list_sort_p(l));
assert (algo_list_sort_p(l));
list_int_clear(l);