What is 'n' doing? (Bubble sort)
Exactly as the title suggested: what is the 'n' for in this code?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
void bubbleSort(int arr[], int n) { // 'n'
bool swapped = true;
int j = 0;
int tmp;
while (swapped) {
swapped = false;
j++;
for (int i = 0; i < n - j; i++) { // 'n'
if (arr[i] > arr[i + 1]) {
tmp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = tmp;
swapped = true;
}
}
}
}
|
The 'n' is a value passed to the function, but if I don't know what it's doing I don't know what to pass...
Thanks
Last edited on
It is the size of the array.
Topic archived. No new replies allowed.