I want to sort an array using bubble sort. I know it's the slowest but i have only 5-10 elements so it's fast enough. My algorithm for bubble sort works cause if I code this

for the arrayCode:void Bubble(int array[], int length, int direction) { int i, j; for (i=0; i<(length-1); i++) { for (j=0; j<(length-i-1); j++) { if (array[j] > array[j+1]) Swap(&array[j], &array[j+1]); } } }i get as expectedCode:884, 275, 470, 890, 860Code:275, 470, 860, 884, 890

I also want the user to determine in which direction the array is sorted, up or down, but here is the problem because I get a stupid response.

but now i get thisCode:void Bubble(int array[], int length, int direction) { int i, j; for (i=0; i<(length-1); i++) { for (j=0; j<(length-i-1); j++) { if (direction == 1) if (array[j] > array[j+1]) Swap(&array[j], &array[j+1]); else if (array[j] < array[j+1]) Swap(&array[j], &array[j+1]); } } }and it's ming boggling why!!Code:860, 890, 470, 275, 884