I don\'t know what I\'m doing wrong but the following code does not sort the array properly.
#include
#include
int compare(
Yeah, your "comparison" overflows. :(
When you subtract a negative number from a positive number, your result is not necessarily positive; if it can't be represented in the data type, it'll "wrap around" the other side.
If your integer can only hold from -8 to 7 (4 bits), then what happens when you compare 4 to -4?
Well, you get 8, which is 1000 in binary, which is -8. So 4 is less than -4.
Don't do subtraction instead of comparison, even if they tell you "look how cool this is" at school!