Skip to content

Commit

Permalink
bubble sort
Browse files Browse the repository at this point in the history
  • Loading branch information
hyejun committed Jun 15, 2020
1 parent f1038b8 commit 00a493b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions bubble sort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <stdio.h>

void bubble_sort(int arr[], int count) {
int temp, i, j;

for (i = 0; i < count; i++) {
for (j = 0; j < count - 1; j++) {
if (arr[j] > arr[j + 1]) {
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}

int main() {
int numArr[10], i;
for (i = 0; i < 10; i++) {
scanf("%d", &numArr[i]);
}
bubble_sort(numArr, sizeof(numArr) / sizeof(int));

for (i = 0; i < 10; i++) {
printf("%d ", numArr[i]);
}
printf("\n");

return 0;
}

0 comments on commit 00a493b

Please sign in to comment.