29bool hanoi(
int *base,
int nel,
int *temp,
int *count,
int *changed,
46 }
else if (nel == 2) {
50 ( changed[n1] || changed[n2]) ? compar(n1, n2) : 0;
55 }
else if (stat < 0) {
75 if (
hanoi(b1, n1, t1, count, changed, compar)) {
76 if (
hanoi(b2, n2, t2, count, changed, compar)) {
85 if (
hanoi(b2, n2, t2, count, changed, compar)) {
98 ( changed[*s1] || changed[*s2]) ? compar(*s1, *s2) : 0;
99 int len1 = count[*s1];
100 int len2 = count[*s2];
104 count[*s1] = len1 + len2;
106 memmove(ptr, s1, len1 *
sizeof(
int));
111 memmove(ptr, s2, n2 *
sizeof(
int));
118 memmove(ptr, s2, len2 *
sizeof(
int));
122 memmove(ptr, s1, n1 *
sizeof(
int));
126 }
else if (stat < 0 && len1 > 0) {
127 memmove(ptr, s1, len1 *
sizeof(
int));
132 memmove(ptr, s2, n2 *
sizeof(
int));
137 }
else if (stat > 0 && len2 > 0) {
138 memmove(ptr, s2, len2 *
sizeof(
int));
142 memmove(ptr, s1, n1 *
sizeof(
int));
154void hanoisort(
int *base,
int nel,
int *count,
int *changed,
155 CompareFunc compar) {
157 std::vector<int> tempVec(nel);
158 if (
detail::hanoi(base, nel, tempVec.data(), count, changed, compar)) {
159 memmove(base, tempVec.data(), nel *
sizeof(
int));
163void hanoisort(std::span<int> &base, std::vector<int> &count,
164 std::vector<int> &changed, CompareFunc compar) {
165 std::vector<int> tempVec(base.size());
166 if (
detail::hanoi(base.data(), base.size(), tempVec.data(), count.data(),
167 changed.data(), compar)) {
168 std::copy(tempVec.begin(), tempVec.end(), base.begin());