Exercise 2.2: Polymorphic sort function