data-structures · beginner · ~15 min
Use modular arithmetic on enum values.
Define enum Dir { NORTH, EAST, SOUTH, WEST }; (clockwise) and implement enum Dir turn_right(enum Dir d) returning the next direction clockwise (WEST turns to NORTH).
enum Dir { NORTH, EAST, SOUTH, WEST };
enum Dir turn_right(enum Dir d) {
/* TODO */
return d;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.