void magic(char* c) {
size_t len = strlen(c);
char temp;
short toggle = 0;
for(size_t it = 0; it < len; it++) {
for(size_t i = toggle; i < len - 1; i+=2) {
temp = c[i]; c[i] = c[i+1]; c[i+1] = temp;
}
toggle = (toggle+1)%2;
}
}
An algorithm that may be useful to constructors of conveyor-belt-driven robot-sorters.