#include "..\CookHeader.h"

Array <int> dataAry ;
int sortCount = 0;

Array <int> bubbleSort(Array <int> ary) {
    int n = len(ary);
    for (int end = n - 1; end > 0; end--) {
        bool changeYN = false;
        for (int cur = 0; cur < end; cur++) {
            sortCount++;
            if (ary[cur] > ary[cur + 1]) {
                int tmp = ary[cur + 1];
                ary[cur + 1] = ary[cur];
                ary[cur] = tmp;
                changeYN = true;
            }
        }
        if (!changeYN)
            break;
    }
    return ary;
}

int main() {
    randomInit(0, 200);
    for (int i = 0; i < 10; i++)
        dataAry.push_back(cookRandom(gen));  // 0~200 사이 랜덤한 숫자
    print("정렬 전 -->");
    printArray(dataAry);
    dataAry = bubbleSort(dataAry);
    print("정렬 후 -->");
    printArray(dataAry);
    println("## " + to_string(sortCount) + "회의 비교로 정렬 완료");
}
