The Theory of Sorting Data

Apart from comparing blocks of data, you will often find that you need to sort a particular set of data. In a base of sorted data, you can locate elements faster and it becomes easier to present output in a certain logical format. Think, for instance, of representing the same information in different contexts: a list of employees ordered by day of birth for a birthday card list, the same list of employees ordered by salary for cost analysis, and so on. It is easier (and faster) for a program to group data according to a certain criterion—for example, an unsorted telephone directory.

In the previous sections, you have already read about a basic mechanism used in sorting—namely, matching patterns of data. Sorting is in ...

Get C++ Footprint and Performance Optimization 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.