2014/02/24

UVa 11462 Age Sort

Note:
Use qsort in <stdlib.h>

http://uva.onlinejudge.org/external/114/11462.html
#include<stdio.h>
#include <stdlib.h>

int cmp(const void *s1, const void *s2);

int main(void){
    int n = 0,i;
    int array[2000005];
    while (scanf("%d",&n)!=EOF && n!=0) {
        for (i = 0; i < n; i++)
            scanf("%d",&array[i]);
        
        qsort(array, n, sizeof(int), cmp);
        printf("%d",array[0]);
        for (i = 1; i < n; i++) {
            printf(" %d",array[i]);
        }
        printf("\n");
    }
    
    return 0;
}

int cmp(const void *s1, const void *s2){
    return *(int *)s1 - *(int *)s2;
}