#include <iostream>
#include <algorithm>
using namespace std;

// 오름차순 비교 함수
bool compare(int a, int b) {
    return a < b;              //a가 b보다 작으면 true → a가 앞으로
}

int main() {
    int arr[5] = {5, 2, 8, 1, 4};

                                   // sort 함수 사용
    sort(arr, arr + 5, compare);

    // 정렬된 배열 출력
    for(int i = 0; i < 5; i++) {
        cout << arr[i] << " ";
    }

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: