Prev | Current Page 44 | Next

Carl Reynolds and Paul Tymann

"Schaum's Outline of Principles of Computer Science"

In this case, we use two variables,
number_index and sorted_index, to keep track of two positions in the list of numbers.
We consider the list as two sets of numbers. We start with only one set of numbers??”the numbers we want
to sort. However, immediately the algorithm considers the list to be comprised of two sets of numbers; the first
???set??? consists of the first number in the original list, and the second set consists of all the rest of the numbers.
The first set is the set of ???sorted??? numbers (like the cards already sorted in your hand), and the second set is the
remaining set of unsorted numbers. The sorted set of numbers starts out containing only a single number, but as the
algorithm proceeds, more and more of the unsorted numbers will be moved to their proper position in the sorted set.
The variable number_index keeps track of where we are in the list of unsorted numbers; it starts at 2,
the first number which is ???unsorted.??? The variable sorted_index keeps track of where we are among the
sorted numbers; it starts at 1, since the first element of the original list starts the set of ???sorted??? numbers.
The algorithm compares the next number to be inserted into the sorted set against the largest of the sorted
numbers.


Pages:
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
spa nad morzem need cash fast bad credit noclegi świnoujście blisko morza Życie Wizytówki Babia Góra