Skip to content

Instantly share code, notes, and snippets.

@calofmijuck
Created August 10, 2022 14:16
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