Hi, I'm having some problems with my coding and was hoping someone might assist me. I'm attempting to use Bubble Sort in C to sort an array of numbers, but the sorting isn't functioning as planned. I'm using the following code:
Code:
void bubbleSort(int arr[], int n) {
int i, j;
for (i = 0; i < n-1; i++) {
for (j = 0; j < n-i-1; j++) {
if (arr[j] > arr[j+1]) {
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
When I execute this code with an integer array, the result is not properly sorted. I'm not sure what the problem is; can somebody tell me what's wrong? I read it from several sources but couldn't fully get it. They gave various examples, but none of them are relevant to my case. Can someone assist them?