Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,16 +1,28 @@
|
|||
void bubble_sort(int *a, int n) {
|
||||
int j, t = 1;
|
||||
while (n-- && t)
|
||||
for (j = t = 0; j < n; j++) {
|
||||
if (a[j] <= a[j + 1]) continue;
|
||||
t = a[j], a[j] = a[j + 1], a[j + 1] = t;
|
||||
t=1;
|
||||
}
|
||||
#include <stdio.h>
|
||||
|
||||
void bubble_sort (int *a, int n) {
|
||||
int i, t, s = 1;
|
||||
while (s) {
|
||||
s = 0;
|
||||
for (i = 1; i < n; i++) {
|
||||
if (a[i] < a[i - 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, sizeof(a) / sizeof(a[0]));
|
||||
|
||||
return 0;
|
||||
int main () {
|
||||
int a[] = {4, 65, 2, -31, 0, 99, 2, 83, 782, 1};
|
||||
int n = sizeof a / sizeof a[0];
|
||||
int i;
|
||||
for (i = 0; i < n; i++)
|
||||
printf("%d%s", a[i], i == n - 1 ? "\n" : " ");
|
||||
bubble_sort(a, n);
|
||||
for (i = 0; i < n; i++)
|
||||
printf("%d%s", a[i], i == n - 1 ? "\n" : " ");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue