/*
employee age sequencing, mainly in the order of counting ideas, time complexity of O (n), the need for a fixed size of additional auxiliary space*/#include<stdio.h>#include<string.h>/*counting sort, employee age can be set between 0-99 void *memset (void *s, int ch, size_t N) function explained: will be the N bytes after the current position in S (typedef unsigned int siz e_t) Replace with CH and return S. Memset: The function is to populate a block of memory with a given value, which is the quickest way to clear 0 operations on a larger struct or array [1]. */voidSortage (intAges[],intLen) { if(ages==null| | len<1) return ; inttimesofage[ -]; memset (Timesofage,0,sizeof(Timesofage)); inti; //calculate the number of employees per age for(i=0; i<len;i++) { if(ages[i]<= About&&ages[i]>=0) Timesofage[ages[i]]++; } //Sort the ages intindex=0; for(i=0;i< -; i++) { intj=0; while(j<Timesofage[i]) {Ages[index++]=i; J++; } }}intMain () {intAges[] = { -, the, $, -, $, at, +, A, +, -, $, the, +, the, the, -, the, A, +, -, -, +, A, +, -, -, -, -, the, in}; intlen= -; Sortage (Ages,len); inti; for(i=0; i<len;i++) printf ("%d", Ages[i]); printf ("\ n"); return 0;}
Age sort (count sort)