Age sort (count sort)

Source: Internet
Author: User

/*
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.