From today to learn two algorithms every day
The first day to learn is "Aha! Algorithm "is a user-friendly method books
A algorithm: Easy bucket sort
The core idea: to create an array, using array sort numeric values, such as values within 100 sorting, first create an array of arrays containing a, (value of 101 values from 0 to 100, for example, int [101] array which is our "bucket" of ) and then use the cycle, the value corresponding to the bucket corresponding to, for example, to 5 on the array a [5] which has a value of 5 on the tub +1 value finally number values sequentially tub output. The outcome sort of
Disadvantages: If the value is too large, such as the need to sort 1-2000000 in value, we need to create more than two million barrels of variable value, extremely memory-intensive. If the value appears name the name represents not take into account value.
#include <stdio.h> int main () { int A [ 101 ], I, J, T; for (I = 0 ; I <= 10 ; I ++ ) A [I] = 0 ; // initializes to 0 for (I = . 1 ; I <= . 5 ; I ++) // cycle number is read. 5 { Scanf ( " % D " , & t); // the number of each of the read variable t A [t] ++; / / counting } for (I = 0; I <= 10 ; I ++) // sequentially determining A [0] ~ A [10] for (J = . 1 ; J <= A [I]; J ++) // there have been several times to print the printf ( " D% " , I); return 0 ; }