[c++] 거품정렬
#include <iostream>
using namespace std;

void bubbleSort(int arr[], int n) {
    for (int i = 0; i < n-1; i++) {
        for (int j = 0; j < n-i-1; j++) {
            if (arr[j] > arr[j+1]) {
                swap(arr[j], arr[j+1]);
            }
        }
    }
}

int main() {
    int arr[] = {64, 34, 25, 12, 22, 11, 90};
    int n = sizeof(arr) / sizeof(arr[0]);
    bubbleSort(arr, n);
    cout << "Sorted array: ";
    for (int i = 0; i < n; i++) {
        cout << arr[i] << " ";
    }
    return 0;
}

이 알고리즘의 기본 개념은 인접한 두 요소를 비교하고 필요에 따라 서로 교환해가며 정렬하는 것입니다. 그러나 큰 리스트에 대해서는 효율성이 매우 낮기 때문에 작은 크기의 리스트나 교유한 목적으로만 사용하는 것이 좋습니다.

거품정렬에 대한 자세한 내용은 다음 참조 자료를 참고하세요.