Sorting algorithms/Bubble sort: Difference between revisions

Content added Content deleted
(→‎{{header|C}}: there is no point in making a local variable const)
Line 227: Line 227:
=={{header|C}}==
=={{header|C}}==
<lang c>void bubble_sort(int *a, int n) {
<lang c>void bubble_sort(int *a, int n) {
int i, j, t=1;
int j, t = 1;
for (i = n - 1; i && t; i--) {
while (n-- && t)
for (j = t = 0; j < i; j++) {
for (j = t = 0; j < n; j++) {
if (a[j] <= a[j + 1]) continue;
if (a[j] <= a[j + 1]) continue;
t = a[j], a[j] = a[j + 1], a[j + 1] = t;

t=1;
t = a[j]; a[j] = a[j + 1]; a[j + 1] = t;
t = 1;
}
}
}
}
}