Sorting
Your programs can sort lists of values in different ways. Perhaps the list was sorted previously, and now you want to reverse the sort. A reversed sort may be appropriate, for example, to print customer balances from the highest balance to the lowest.
Consider the following list of numbers that is not sorted:
10 54 34 46 23
Here is the list sorted in ascending order (from lowest to highest):
10 23 34 46 54
Here is the list sorted in descending order (from highest to lowest):
54 46 34 23 10
Of course, your program can also sort character string data, such as a list of names. When sorting strings, the computer uses the ASCII table to sort the values in alphabetical order.
There are several ways to sort data. The most popular one for beginning ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access