Skip to main content

Practice ยท 4 of 4

Choosing Order at Runtime

Implement a sort that picks its comparator from a mode argument: ``c /* mode 0: ints ascending; mode 1: ints descending. Other modes leave the array untouched. Returns the mode used or -1. */ int sort_i_mode(int *arr, size_t n, int mode); /* a driver that inspects the array and reports its current order: 0 = already ascending, 1 = already descending, -1 = neither. */ int which_mode_sorted(int *arr, size_t n); ``

Difficulty: intermediate

Back to lesson: Practice: Dispatch & Context Gym