Monday, 27 January 2014

Sort the numbers in non-decreasing order (Turbo sort)

    #include <stdio.h>
    #define MAX 1000001
    int nums[MAX];
  
    int main(){
    int n;
    int x;
    for(x=0; x<MAX; x++)
    nums[x] = 0;
    scanf("%d", &n);
    while(n--){
    scanf("%d", &x);
    ++nums[x];
    }
    for(x=0; x<MAX; x++)
    while(nums[x]--)
    printf("%d\n", x);
    return 0;
}

No comments:

Post a Comment