Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Thiết lập lại phương pháp () được thực hiện bởi vì các lớp Ienumerator yêu cầu nó. Tất cả nó làm là thiết lập các chỉ số trở lại -1 khi thích hợp. Bây giờ chúng ta có tất cả các mã tại chỗ, chúng ta có thể sử dụng lớp CEnumerator để liệt kê bộ sưu tập tùy chỉnh của chúng ta về các yếu tố. | 116 STACKS AND QUEUES Here s the output from a sample run using our data Sorting Data with Queues Queues are also useful for sorting data. Back in the old days of computing programs were entered into a mainframe computer via punch cards where each card held a single program statement. Cards were sorted using a mechanical sorter that utilized binlike structures. We can simulate this process by sorting data using queues. This sorting technique is called a radix sort. It will not be the fastest sort in your programming repertoire but the radix sort does demonstrate another interesting use of queues. The radix sort works by making two passes over a set of data in this case integers in the range 0-99. The first pass sorts the numbers based on the 1 s digit and the second pass sorts the numbers based on the 10 s digit. Each number is then placed in a bin based on the digit in each of these places. Given the numbers 91 46 85 15 92 35 31 22 the first pass results in this bin configuration Bin 0 Bin 1 91 31 Bin 2 92 22 Bin 3 Bin 4 Bin 5 85 15 35 Bin 6 46 Bin 7 Bin 8 Bin 9 Queues the Queue Class and a Queue Class Implementation 117 Now put the numbers in order based on which bin they re in 91 31 92 22 85 15 35 46 Next take the list and sort by the 10 s digit into the appropriate bins Bin 0 Bin 1 15 Bin 2 22 Bin 3 31 35 Bin 4 46 Bin 5 Bin 6 Bin 7 Bin 8 85 Bin 9 91 92 Take the numbers from the bins and put them back into a list which results in a sorted set of integers 15 22 31 35 46 85 91 92 We can implement this algorithm by using queues to represent the bins. We need nine queues one for each digit. We use modulus and integer division for determining the 1 s and 10 s digits. The rest entails adding numbers to their appropriate queues taking them out of the queues to resort based on the 1 s digit and then repeating the process for the 10 s digit. The result is a sorted list of integers. Here s the code Module Modulel Enum DigitType ones 1 tens 10 End Enum Sub Main Dim .