Created
August 10, 2022 14:16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void bubble_sort(vector<int>& arr) { | |
int n = (int) arr.size(); | |
for (int i = 0; i < n - 1; ++i) { | |
// 정렬되지 않은 영역의 마지막까지 정렬 | |
for (int j = 0; j < n - 1 - i; ++j) { | |
// 왼쪽의 원소가 더 크면 | |
if (arr[j] > arr[j + 1]) { | |
// 둘의 자리를 바꿈 | |
swap(arr[j], arr[j + 1]); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment