Search
 
SCRIPT & CODE EXAMPLE
 

C

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];
    }
  }
}
Comment

PREVIOUS NEXT
Code Example
C :: translator program in c 
C :: first come first serve 
C :: set all pins as input for loop 
C :: overhead computer science 
C :: input multipal data types 
C :: ESP32 timerBegin(0, cpuClock, true); 
C :: c math.h sqrt 
C :: fraction sum c 
C :: Entering raw mode 
C :: transform yt video into background overlay 
C :: how to compress a file in c 
C :: data breach 
C :: shortest job first 
C :: how to know a type of a numbe in c 
C :: c how to include variables of other c file 
C :: search and then change string -- strstr and strcpy 
C :: Trasmettere variabile float attraverso seriale 
C :: string once declared 
C :: Program optimization 
C :: c ternary operator 
C :: time now C 
C :: babel customelement plugins 
Dart :: flutter column center horizontal text 
Dart :: flutter check if string is number dart 
Dart :: dart round to 2 decimals 
Dart :: dart yaxlitlash 
Dart :: flutter date time to timestamp 
Dart :: flutter button with icon 
Dart :: how to disable screen rotation in flutter 
Dart :: flutter linearprogressindicator value 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =