반응형
#include<stdio.h>
void bubble_sort(int arr[], int count){
int temp;
for(int i = 0; i < count; i ++){
for(int 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] = {5,6,7,8,2,3,4,1,22,45};
bubble_sort(numArr, sizeof(numArr)/sizeof(int));
for (int i = 0 ; i < 10; i++){
printf("%d",numArr[i]);
}
printf("\n");
return 0;
}
반응형
LIST
'알고리즘' 카테고리의 다른 글
알고리즘을 하자 (너비 우선 탐색) (0) | 2021.10.06 |
---|---|
알고리즘을 하자 (삽입 정렬) (0) | 2021.05.26 |
시간복잡도 (0) | 2021.05.12 |
알고리즘을 하자 (선택 정렬) (0) | 2021.05.05 |
알고리즘을 하자 (swap함수) (0) | 2021.04.28 |