1、- 1 - 外文原文 Simple Sorting Overview As soon as you create a significant database, youll probably think of reasons to sort it in various ways. You need to arrange names in alphabetical order, students by grade, customers by zip code, home sales by price, cities in order of increasing population, count
2、ries by GNP, stars by magnitude, and so on. Sorting data may also be a preliminary step to searching it. As a binary search, which can be applied only to sorted data, is much faster than a linear search. Sorting is so important and potentially so time-consuming,it has been the subject of extensive r
3、esearch in computer science, and some very sophisticated methods have been developed. In this chapter well look at three of the simpler algorithms: the bubble sort, the selection sort, and the insertion sort. The techniques described in this chapter, while unsophisticated and comparatively slow, are
4、 nevertheless worth examining. Besides being easier to understand, they are actually better in some circumstances than the more sophisticated algorithms. The sorting algorithms are implemented as methods of similar array classes. Be sure to try out the Workshop applets included in this chapter. They
5、 are more effective in explaining how the sorting algorithms work than prose and static pictures could ever be. How Would Y ou Do It? Imagine that your kids-league baseball team is lined up on the field, The regulation nine players, plus an extra, have shown up for practice. You want to arrange the
6、players in order of increasing height (with the shortest player on the left), for the team picture. How would you go about this sorting process? As a human being, you have advantages over a computer program. You can see all the kids at once, and you can pick out the tallest kid almost instantly; you dont need to laboriously measure and compare everyone. Also, the kids dont need to occupy particular places. They can jostle each other, push each other a little to make room, and stand be