본문 바로가기
Algorithm

Bubble Sort

by orioncsy 2022. 10. 6.
//c++, bubble sort
void swap(int* a, int* b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

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

'Algorithm' 카테고리의 다른 글

Merge Sort  (0) 2022.10.11
Radix Sort  (0) 2022.10.11
Insertion sort  (1) 2022.10.07
Quick Sort  (0) 2022.10.06
[알고리즘] Base  (0) 2022.09.28