Sorting algorithms/Bubble sort: Difference between revisions

→‎{{header|C}}: Avoid too many actions on one line. Use another variable to track when swaps happen vs the swap temporary.
(Add Nimrod)
(→‎{{header|C}}: Avoid too many actions on one line. Use another variable to track when swaps happen vs the swap temporary.)
Line 359:
 
=={{header|C}}==
}</lang c>
<lang c>void bubble_sort(int *a, int n) {
void bubble_sort (int j*a, tint =n) 1;{
int i, t, s = 1;
while (n-- && t)
for (j = t =while 0; j < n; j++(s) {
if (a[j] <= a[j + 1]) continue s = 0;
t = a[j], a[j] = a[j + 1], a[jfor +(i = 1]; =i t< n; i++) {
if (a[i] < a[i - 1]) {
t=1;
t = a[i];
}
a[i] = a[i - 1];
a[i - 1] = t;
s = 1;
}
}
}
}
 
int main (void) {
int a[] = {4, 65, 2, -31, 0, 99, 2, 83, 782, 1};
bubble_sort(a, int n = sizeof( a) / sizeof( a[0]));
<lang c>void bubble_sort(int *a, int n) {;
 
return 0;
}
}</lang>
</lang>
 
=={{header|C++}}==