© Giulio Zambon 2016

Giulio Zambon, Practical C, 10.1007/978-1-4842-1769-6_9

9. Sorting

Giulio Zambon

(1)Harrison, Aust Capital Terr, Australia

In the previous chapter, you read about ordered arrays and binary trees. In particular, you learned how to work with ordered arrays of pointers to insert, delete, and find individual items.

In this chapter, you will learn methods to bring order to unordered arrays.

Insertion Sort

The simplest way to sort an array is to go through its elements one by one and move them to their correct positions. This is what you do when you sort the cards in your hand while playing a card game.

Listing 9-1 shows how easy it is to apply insertion sort to an array of pointers.

Listing 9-1. sort_insertion()
 1. //-------------------------------------------------------------- ...

Get Practical C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.