data-structures · beginner · ~15 min

Is it sorted?

Verify an ordering invariant.

Challenge

Implement int is_sorted(const int *a, int n) returning 1 if the array is non-decreasing, else 0.

Starter code

int is_sorted(const int *a, int n) {
    /* TODO */
    return 1;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.