Computer Science/Algorithm
[정렬#1] 버블 정렬(Bubble Sort)
89점
2015. 10. 10. 12:39
기본적인 아이디어는 인근의 두 수를 비교해서 정렬하는 것.
1234567891011121314151617181920 int main(){int a[10] = { 10, 2, 3, 5, 1, 7, 9, 8, 6, 4 };for (int i = 0; i < 10; i++){for (int j = 0; j < 10 - i - 1; j++){if (a[j] > a[j + 1]){int temp = a[j];a[j] = a[j + 1];a[j + 1] = temp;}}}for (int i = 0; i < 10; i++){cout << a[i] << " ";}cout << endl;return 0;}cs
시간복잡도는