#include <iostream>
using namespace std;
int main(){
int array[] = {1,10,5,8,7,6,4,3,2,9};
for(int i=0; i<sizeof(array)/sizeof(int); i++){
for(int j=0; j<(sizeof(array)/sizeof(int))-1-i; j++){
if(array[j]<array[j+1]){
int temp=array[j+1];
array[j+1]=array[j];
array[j]=temp;
}
}
}
for(int i=0; i<sizeof(array)/sizeof(int); i++){
cout<<array[i]<<" ";
}
cout<<endl;
system("pause");
return 0;
}
10 9 8 7 6 5 4 3 2 1
출처 :https://gmlwjd9405.github.io/2018/05/06/algorithm-bubble-sort.html
[알고리즘] 버블 정렬(bubble sort)이란 - Heee's Development Blog
Step by step goes a long way.
gmlwjd9405.github.io
'C++ 알고리즘 > 5. 정렬 알고리즘' 카테고리의 다른 글
선택 알고리즘 (시간 복잡도 O(N^2) ) (0) | 2019.09.01 |
---|---|
정렬 알고리즘 시간 복잡도 비교 (0) | 2019.09.01 |
댓글