1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int BubbleSort(int arr[]) {
 
    for (int i = 0; i < SIZE - 1; i++) {
        bool flag = false;
        for (int j = 0; j < SIZE - 1 - i; j++) {
            if (arr[j] > arr[j + 1]) {
                Swap(&arr[j], &arr[j + 1]);
                flag = true;
            }
        }
        if (flag == false)
            break;
    }
    
    cout << "Bubble Sort" << endl;
    Print(arr);
    return 0;
}
 
cs


'알고리즘' 카테고리의 다른 글

InsertSort  (0) 2018.05.26
SelectionSort  (0) 2018.05.26
MergeSort  (0) 2018.05.26
Quick Sort  (0) 2018.05.26
Heap Sorting  (0) 2018.05.26

+ Recent posts