#include <stdio.h>
int n = 7;
int bil[] = {5, 3, 8, 4, 7, 2, 1};
void swap(int first, int second) {
int tampung = bil[first];
bil[first] = bil[second];
bil[second] = tampung;
}
void bubbleSort() {
int x, y;
for (x = 1; x < n; x++) {
for (y = 0; y < n - x; y++) {
if (bil[y] > bil[y + 1]) {
swap(y, (y + 1));
}
}
}
}
int main() {
bubbleSort();
int x;
for (x = 0; x < n; x++) {
printf("%d ", bil[x]);
}
return 0;
}
No comments:
Post a Comment