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)) {
83 if (
hanoi(b2, n2, t2, count, changed, compar)) {
96 ( changed[*s1] || changed[*s2]) ? compar(*s1, *s2) : 0;
97 int len1 = count[*s1];
98 int len2 = count[*s2];
102 count[*s1] = len1 + len2;
104 memmove(ptr, s1, len1 *
sizeof(
int));
109 memmove(ptr, s2, n2 *
sizeof(
int));
116 memmove(ptr, s2, len2 *
sizeof(
int));
120 memmove(ptr, s1, n1 *
sizeof(
int));
124 }
else if (stat < 0 && len1 > 0) {
125 memmove(ptr, s1, len1 *
sizeof(
int));
130 memmove(ptr, s2, n2 *
sizeof(
int));
135 }
else if (stat > 0 && len2 > 0) {
136 memmove(ptr, s2, len2 *
sizeof(
int));
140 memmove(ptr, s1, n1 *
sizeof(
int));
150 template <
typename CompareFunc>
151 void hanoisort(
int *base,
int nel,
int *count,
int *changed,
152 CompareFunc compar) {
154 int *temp = (
int *)malloc(nel *
sizeof(
int));
156 if (
hanoi(base, nel, temp, count, changed, compar)) {
157 memmove(base, temp, nel *
sizeof(
int));
163 #if defined(_MSC_VER)
bool hanoi(int *base, int nel, int *temp, int *count, int *changed, CompareFunc compar)
void hanoisort(int *base, int nel, int *count, int *changed, CompareFunc compar)