22 #pragma warning(push, 1)
23 #pragma warning(disable : 4800)
26 template <
typename CompareFunc>
27 bool hanoi(
int *base,
int nel,
int *temp,
int *count,
int *changed,
44 }
else if (nel == 2) {
48 ( changed[n1] || changed[n2]) ? compar(n1, n2) : 0;
53 }
else if (stat < 0) {
73 if (
hanoi(b1, n1, t1, count, changed, compar)) {
74 if (
hanoi(b2, n2, t2, count, changed, compar)) {
82 if (
hanoi(b2, n2, t2, count, changed, compar)) {
94 ( changed[*s1] || changed[*s2]) ? compar(*s1, *s2) : 0;
95 int len1 = count[*s1];
96 int len2 = count[*s2];
100 count[*s1] = len1 + len2;
102 memmove(ptr, s1, len1 *
sizeof(
int));
106 if (ptr != s2) memmove(ptr, s2, n2 *
sizeof(
int));
112 memmove(ptr, s2, len2 *
sizeof(
int));
116 memmove(ptr, s1, n1 *
sizeof(
int));
120 }
else if (stat < 0 && len1 > 0) {
121 memmove(ptr, s1, len1 *
sizeof(
int));
125 if (ptr != s2) memmove(ptr, s2, n2 *
sizeof(
int));
129 }
else if (stat > 0 && len2 > 0) {
130 memmove(ptr, s2, len2 *
sizeof(
int));
134 memmove(ptr, s1, n1 *
sizeof(
int));
144 template <
typename CompareFunc>
145 void hanoisort(
int *base,
int nel,
int *count,
int *changed,
146 CompareFunc compar) {
148 int *temp = (
int *)malloc(nel *
sizeof(
int));
150 if (
hanoi(base, nel, temp, count, changed, compar))
151 memmove(base, temp, nel *
sizeof(
int));
156 #if defined(_MSC_VER)