Solve Exercise 5-17: field sorting