Before the Post wrote the Exchange (bubbling) sort, select sort, this article write bucket sort. But I understand that this is not really the sort of barrels, my relatively simple and real bucket sort is more complicated, for the moment, call the bucket sort it.
Bucket sorting in the sort should not be used much, personal understanding is relatively easy to understand, for a small number of data sorting is very useful, but there is a minor drawback is only suitable for printing on the screen output, the actual application we are using this arrangement after the data, I think this is the bucket sorting application less reasons for it.
So let's just say it, so the name of the bucket is a row with serial number of the bucket, and the range of this number is to include the data we want to sort. When we enter the data will be marked with the same number of input data on the bucket labeled once, each time the input data in the same number of data on the bucket marked once, so that the number of times each data appear is obvious, and the sorting is good, we follow the numbering sequence of the unmarked bucket excluded, Then print the same number of times according to the number of times the bucket is marked.
#include"stdio.h"intMainvoid){ intI, J; intN, b[Ten] = {};//First, reset all the bucket's marks to 0 for(j =0; J <Ten; J + +) {scanf ("%d", &n);//read 10 of data in turnB[n] + +; } for(i =0; I <Ten; i + +) for(j =0; J < B[i]; J + +)//print data based on number of times
0 without a mark, then it won't print.printf"%d", i);}
Of course, there are 10 or less data for example input 4 4 5 6 1 0 4 4 6 8 output result is 0 1 4 4 4 4 5 6 6 8
Adjust the range of the data yourself, change the size of the array, change the range of the for so that it can be included so that at least you can save some time.
#include"stdio.h"//sort four-digitintMainvoid){ intI, J; intN, b[10000] = {};//resizing an array for(j =0; J <Ten; J + +) {scanf ("%d", &n);//read 10 of data in turnB[n] + +; } for(i = +; I <10000; i + +)//Adjustment Range for(j =0; J < B[i]; J + +) printf ("%d", i);}
as modified on the above can be used to sort the four-digit input data 3234 6535 8743 9876 4567 5466 5434 2345 8798 4323 input result 2345 3234 4323 4567 5434 5466 6535 8743 8798 9876
The actual use of the actual changes I personally understand the bucket sort is very simple but the real bucket sort is a bit more complicated I just understand under the need to go into the Baidu Google Kazakhstan
C Language Learning Bucket sorting