go to previous page   go to home page   go to next page

Answer:

Here are the integers in order:

Your browser does not support the HTML 5 Canvas.

Sorted Order

For this chapter and the next several chapters, the input to the sorting algorithms will be an array of integers. In general, any type of data can be sorted. But for now, let's stick to integers.

When is a list of integers sorted? Which of the following lists are sorted?

ListIs it Sorted?             Observation           
1, 3, 5, 9, 23, 45, 56
23, 45, 45, 56, 67, 78, 78, 136
-4, -2, 0, 0, 12, 17
5, 2, 3, 6, 9, 12
-12, -12, -5, -6, -3, 0
5, 5, 5, 5, 5, 5, 5, 5
-2, -5, -45, -89

A list of integers is sorted in ascending order from left to right if each integer is followed by an equal or larger integer.

In general, the same integer may occur more than once in the list. (In some specific applications this might not be allowed.) And, in general, negative integers and the integer zero are allowed.

BUG ALERT: it is easy to be fooled by negative values. (See the last example, above.) A negative integer with a large absolute value should preceed a negative integer with a smaller absolute value. Another way to look at this is that the integers should be arranged in the order they lie on the number line.


QUESTION 2:

Could a list of integers be sorted into descending order?