diff options
-rw-r--r-- | 16.c | 20 |
1 files changed, 7 insertions, 13 deletions
@@ -100,13 +100,6 @@ ptrcmp(void const * a, void const * b) } -int -ptrcmpr(void const * a, void const * b) -{ - return *((void **) b) - *((void **) a); -} - - struct valve { char name[3]; int flow; @@ -389,12 +382,13 @@ main(int argc, char ** argv) if (i < nflows) { // We didn't get to the end of the path. We can skip all // the permutations of all the remaining elements in the - // path, because they don't matter. Do this by sorting - // the remining elements in reverse, which is the last - // possible permutation, so that the qpermute() will - // pick the next path that is substantively different - // from this. - qsort(path + i + 1, nflows - (i + 1), sizeof(struct valve *), ptrcmpr); + // path, because they don't matter. + // Remaining elements will be in their first possible + // permutation, i.e. in sorted order. If we reverse this + // they'll be in their last permutation, and qpermute() + // will then pick the next path that is substantively + // different from this. + qreverse(path + i + 1, nflows - (i + 1), sizeof(struct valve *)); } } while (qpermute(path, nflows, sizeof(struct valve *), ptrcmp)); |