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,
40 }
else if (nel == 2) {
44 ( changed[n1] || changed[n2]) ? compar(n1, n2) : 0;
49 }
else if (stat < 0) {
69 if (
hanoi(b1, n1, t1, count, changed, compar)) {
70 if (
hanoi(b2, n2, t2, count, changed, compar)) {
78 if (
hanoi(b2, n2, t2, count, changed, compar)) {
90 ( changed[*s1] || changed[*s2]) ? compar(*s1, *s2) : 0;
91 int len1 = count[*s1];
92 int len2 = count[*s2];
96 count[*s1] = len1 + len2;
98 memmove(ptr, s1, len1 *
sizeof(
int));
102 if (ptr != s2) memmove(ptr, s2, n2 *
sizeof(
int));
108 memmove(ptr, s2, len2 *
sizeof(
int));
112 memmove(ptr, s1, n1 *
sizeof(
int));
116 }
else if (stat < 0 && len1 > 0) {
117 memmove(ptr, s1, len1 *
sizeof(
int));
121 if (ptr != s2) memmove(ptr, s2, n2 *
sizeof(
int));
125 }
else if (stat > 0 && len2 > 0) {
126 memmove(ptr, s2, len2 *
sizeof(
int));
130 memmove(ptr, s1, n1 *
sizeof(
int));
140 template <
typename CompareFunc>
141 void hanoisort(
int *base,
int nel,
int *count,
int *changed,
142 CompareFunc compar) {
145 temp = (
int *)malloc(nel *
sizeof(
int));
146 if (
hanoi(base, nel, temp, count, changed, compar))
147 memmove(base, temp, nel *
sizeof(
int));
152 #if defined(_MSC_VER)
void hanoisort(int *base, int nel, int *count, int *changed, CompareFunc compar)
bool hanoi(int *base, int nel, int *temp, int *count, int *changed, CompareFunc compar)