You can do this by walking the array once, from 0 to it's last element. You just need to think about what you need to compare or swap the "current" element against, and it becomes quite easy.
You'll have to keep a few extra variables around to track the current element, and the "other" element you need to compare it to.
Also, you might want to look into the major C code formatting styles. There is no style that makes everyone 100% happy, but there are plenty of styles that make everyone unhappy.
---- Edited ----
Ok, this is much more like a "brain teaser" problem than a serious computer science problem. The issue is that "extra memory" is very poorly defined, and so there's a tons of way you can achieve the outcome if you only remember that recursion is allowed in the programming language, and that a recursive call requires extra stack (which nobody is going to consider memory allocation as it required by the programming language implementation).
Basically, such a question is meant to see if you look at a problem and see a recursive solution.
#include <stdio.h>
void sort(int index, int start1, int end1, int start2, int end2, int* array) {
if (index >= end2) {
return;
}
int lower;
if (array[start1] <= array[start2]) {
lower = array[start1];
sort(index+1, start1+1, end1, start2, end2, array);
} else {
lower = array[start2];
sort(index+1, start1, end1, start2+1, end2, array);
}
array[index]=lower;
}
int main(int argc, char** argv) {
int a[] = {1,3,6,8,-5,-2,3,8};
sort(0, 0, 3, 4, 7, a);
int i;
for (i = 0; i <= 7; i++) {
printf("%d, ", a[i]);
}
printf("\n");
return 0;
}
Is it a cheat? You decide. However, the sort was done in-place, and the cached numbers were neatly tucked away in local space in the call the stack, where you cannot really allocate / de-allocate them.
Extra optimizations are possible, but they are improvements of the core idea: use recursion and the call stack to cache information.