tailieunhanh - Computer Programming for Teens phần 10
Sắp xếp một danh sách các số có nghĩa là sắp xếp chúng tăng dần hoặc giảm dần theo thứ tự. Thứ tự tăng dần sắp xếp số nhỏ hơn trước khi số lượng lớn hơn trong một mảng. Thứ tự giảm dần đặt số lượng lớn kích thước đầu tiên, tiếp theo là số nhỏ hơn. Tiếp theo, | 296 Chapter 19 Let s Put Things in Order Sorting rearranges each pair Figure The array is shown as the merging of these two ordered halves. Each member from each half goes into its proper position. Summary Sorting means arranging data in order. Arranging a list of names in alphabetical order is an example of sorting. Sorting a list of numbers means arranging them in ascending or descending order. Ascending order arranges smaller numbers before larger numbers in an array. Descending order puts numbers that are greater in size first followed by smaller numbers. Next we covered the selection sort which relies on the ability to find the minimum in a list. The selection sort was explained through an analogy of people attending a party. Then we looked at the selection sort applied to a list of numbers. Next we defined the minimum of a list. It is the smallest number in a list. In order to find the smallest number the first number from the array slot 0 is assigned to a variable called minimum. Then the algorithm works by looking at the rest of the numbers in the list one at a time through the use of a loop. As you look at each number you test whether that number is smaller than the number that is presently assigned to the minimum variable. When the loop is done spinning the value in the minimum variable is the smallest number in the list. 297 Summary The merge sort was the second sort we examined. It works very differently from the selection sort. The merge sort repeatedly cuts an array into halves until there are only single elements of the array. Then those members of the array are assembled into their proper order two pieces at a time. The sort gets its name from the merging that occurs as the pieces are put back together properly. This page intentionally left .
đang nạp các trang xem trước