21 #pragma warning(push, 1) 22 #pragma warning(disable: 4800) 25 template <
typename CompareFunc>
26 bool hanoi(
int *base,
int nel,
int *temp,
int *count,
int *changed,
39 }
else if (nel == 2) {
43 ( changed[n1] || changed[n2]) ? compar(n1, n2) : 0;
48 }
else if (stat < 0) {
68 if (
hanoi(b1, n1, t1, count, changed, compar)) {
69 if (
hanoi(b2, n2, t2, count, changed, compar)) {
77 if (
hanoi(b2, n2, t2, count, changed, compar)) {
89 ( changed[*s1] || changed[*s2]) ? compar(*s1, *s2) : 0;
90 int len1 = count[*s1];
91 int len2 = count[*s2];
95 count[*s1] = len1 + len2;
97 memmove(ptr, s1, len1 *
sizeof(
int));
101 if (ptr != s2) memmove(ptr, s2, n2 *
sizeof(
int));
107 memmove(ptr, s2, len2 *
sizeof(
int));
111 memmove(ptr, s1, n1 *
sizeof(
int));
115 }
else if (stat < 0 && len1 > 0) {
116 memmove(ptr, s1, len1 *
sizeof(
int));
120 if (ptr != s2) memmove(ptr, s2, n2 *
sizeof(
int));
124 }
else if (stat > 0 && len2 > 0) {
125 memmove(ptr, s2, len2 *
sizeof(
int));
129 memmove(ptr, s1, n1 *
sizeof(
int));
139 template <
typename CompareFunc>
140 void hanoisort(
int *base,
int nel,
int *count,
int *changed,
141 CompareFunc compar) {
144 temp = (
int *)malloc(nel *
sizeof(
int));
145 if (
hanoi(base, nel, temp, count, changed, compar))
146 memmove(base, temp, nel *
sizeof(
int));
151 #if defined(_MSC_VER) void hanoisort(int *base, int nel, int *count, int *changed, CompareFunc compar)
Includes a bunch of functionality for handling Atom and Bond queries.
bool hanoi(int *base, int nel, int *temp, int *count, int *changed, CompareFunc compar)