Horje
counting sort using malloc and size-t type c Code Example
counting sort using malloc and size-t type c
#include <stdio.h>
#include <stdlib.h>

void counting_sort_mm(int *array, int n, int min, int max)
{
  int i, j, z;

  int range = max - min + 1;
  int *count = malloc(range * sizeof(*array));

  for(i = 0; i < range; i++) count[i] = 0;
  for(i = 0; i < n; i++) count[ array[i] - min ]++;

  for(i = min, z = 0; i <= max; i++) 
  {
    for(j = 0; j < count[i - min]; j++) 
    {
      array[z++] = i;
    }
  } 

  free(count);
}

void counting_sort(int *array, int n)
{
  int i, min, max;

  min = max = array[0];
  for(i=1; i < n; i++) 
  {
    if ( array[i] < min ) 
    {
      min = array[i];
    } else if ( array[i] > max ) 
    {
      max = array[i];
    }
  }
}




C

Related
Algorithm that flips sentences and numbers Code Example Algorithm that flips sentences and numbers Code Example
c program to find minimum of 5 numbers using conditional operator in c Code Example c program to find minimum of 5 numbers using conditional operator in c Code Example
PDO Crud Code Example PDO Crud Code Example
esp32 dhcp server Code Example esp32 dhcp server Code Example
google sheets transpose new line to table Code Example google sheets transpose new line to table Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10