Sorting algorithms/Bubble sort: Difference between revisions
Content added Content deleted
Line 605: | Line 605: | ||
void bubble_sort (int *a, int n) { |
void bubble_sort (int *a, int n) { |
||
int i, t, s = 1; |
int i, t, j = n, s = 1; |
||
while (s) { |
while (s) { |
||
s = 0; |
s = 0; |
||
for (i = 1; i < |
for (i = 1; i < j; i++) { |
||
if (a[i] < a[i - 1]) { |
if (a[i] < a[i - 1]) { |
||
t = a[i]; |
t = a[i]; |
||
Line 616: | Line 616: | ||
} |
} |
||
} |
} |
||
j--; |
|||
} |
} |
||
} |
} |