26bool hanoi(
int *base,
int nel,
int *temp,
int *count,
int *changed,
43 }
else if (nel == 2) {
47 ( changed[n1] || changed[n2]) ? compar(n1, n2) : 0;
52 }
else if (stat < 0) {
72 if (
hanoi(b1, n1, t1, count, changed, compar)) {
73 if (
hanoi(b2, n2, t2, count, changed, compar)) {
82 if (
hanoi(b2, n2, t2, count, changed, compar)) {
95 ( changed[*s1] || changed[*s2]) ? compar(*s1, *s2) : 0;
96 int len1 = count[*s1];
97 int len2 = count[*s2];
101 count[*s1] = len1 + len2;
103 memmove(ptr, s1, len1 *
sizeof(
int));
108 memmove(ptr, s2, n2 *
sizeof(
int));
115 memmove(ptr, s2, len2 *
sizeof(
int));
119 memmove(ptr, s1, n1 *
sizeof(
int));
123 }
else if (stat < 0 && len1 > 0) {
124 memmove(ptr, s1, len1 *
sizeof(
int));
129 memmove(ptr, s2, n2 *
sizeof(
int));
134 }
else if (stat > 0 && len2 > 0) {
135 memmove(ptr, s2, len2 *
sizeof(
int));
139 memmove(ptr, s1, n1 *
sizeof(
int));
150void hanoisort(
int *base,
int nel,
int *count,
int *changed,
151 CompareFunc compar) {
153 int *temp = (
int *)malloc(nel *
sizeof(
int));
155 if (
hanoi(base, nel, temp, count, changed, compar)) {
156 memmove(base, temp, nel *
sizeof(
int));
bool hanoi(int *base, int nel, int *temp, int *count, int *changed, CompareFunc compar)