source/algorithms/countingSort.c
void countingSort(int vector[], int vector_size)
{
    int i;
    int output[vector_size];
    int max = largest(vector, vector_size);
    int* counter = (int*)calloc((max+1), sizeof(int));

    for (i = 0; i < vector_size; i++)
    {
        counter[vector[i]]++;
    }

    for (i = 1; i <= max; i++)
    {
        counter[i] += counter[i-1];
    }

    for (i = vector_size - 1; i >= 0; i--)
    {
        output[counter[vector[i]]-1] = vector[i];
        counter[vector[i]]--;
    }

    free(counter);
    copyVector(output, vector, vector_size);
}
//C implementation of counting sort.
//Receives a integer vector and it's size as input.

C implementation of counting sort.
Receives a integer vector and it's size as input.
C implementation of counting sort . Receives a integer vector and it ' s size as input .
void countingSort(int vector[], int vector_size)
{
    int i;
    int output[vector_size];
    int max = largest(vector, vector_size);
    int* counter = (int*)calloc((max+1), sizeof(int));
    for (i = 0; i < vector_size; i++)
    {
        counter[vector[i]]++;
    }
    for (i = 1; i <= max; i++)
    {
        counter[i] += counter[i-1];
    }
    for (i = vector_size - 1; i >= 0; i--)
    {
        output[counter[vector[i]]-1] = vector[i];
        counter[vector[i]]--;
    }
    free(counter);
    copyVector(output, vector, vector_size);
}
void countingSort ( int vector [ ] , int vector_size ) { int i ; int output [ vector_size ] ; int max = largest ( vector , vector_size ) ; int * counter = ( int * ) calloc ( ( max + 1 ) , sizeof ( int ) ) ; for ( i = 0 ; i < vector_size ; i ++ ) { counter [ vector [ i ] ] ++ ; } for ( i = 1 ; i <= max ; i ++ ) { counter [ i ] += counter [ i - 1 ] ; } for ( i = vector_size - 1 ; i >= 0 ; i -- ) { output [ counter [ vector [ i ] ] - 1 ] = vector [ i ] ; counter [ vector [ i ] ] -- ; } free ( counter ) ; copyVector ( output , vector , vector_size ) ; }
C implementation of counting sort.
C implementation of counting sort .