21 template <
typename CompareFunc>
22 bool hanoi(
int* base,
int nel,
int *temp,
int *count,
int *changed, CompareFunc compar ) {
34 }
else if( nel == 2 ) {
37 int stat = (changed[n1]||changed[n2]) ? compar(n1,n2) : 0;
42 }
else if( stat < 0 ) {
55 n1 = nel/2; n2 = nel-n1;
57 b2 = base+n1; t2 = temp+n1;
59 if(
hanoi(b1,n1,t1,count,changed,compar) ) {
60 if(
hanoi(b2,n2,t2,count,changed,compar) ) {
67 if(
hanoi(b2,n2,t2,count,changed,compar) ) {
77 int stat = (changed[*s1]||changed[*s2]) ? compar(*s1,*s2) : 0;
78 int len1 = count[*s1];
79 int len2 = count[*s2];
83 count[*s1] = len1+len2;
85 memmove(ptr,s1,len1*
sizeof(
int));
86 ptr += len1; n1 -= len1;
89 memmove(ptr,s2,n2*
sizeof(
int));
95 memmove(ptr,s2,len2*
sizeof(
int));
96 ptr += len2; n2 -= len2;
98 memmove(ptr,s1,n1*
sizeof(
int));
102 }
else if( stat < 0 && len1>0 ) {
103 memmove(ptr,s1,len1*
sizeof(
int));
104 ptr += len1; n1 -= len1;
107 memmove(ptr,s2,n2*
sizeof(
int));
111 }
else if (stat > 0 && len2>0) {
112 memmove(ptr,s2,len2*
sizeof(
int));
113 ptr += len2; n2 -= len2;
115 memmove(ptr,s1,n1*
sizeof(
int));
125 template <
typename CompareFunc>
126 void hanoisort(
int* base,
int nel,
int *count,
int *changed, CompareFunc compar )
130 temp = (
int*)malloc(nel*
sizeof(
int));
131 if(
hanoi(base,nel,temp,count,changed,compar) )
132 memmove(base,temp,nel*
sizeof(
int));
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)