Counting Sort

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define MAX_VALUE 10001

int n, m;
int a[MAX_VALUE];

int main()
{
    printf("Count : ");
    scanf("%d", &n);
    printf("\r\n\r\n");
    for (int i = 0; i < n; i++) {
        printf("a[%d] : ", i);
        scanf("%d", &m); 
        a[m]++; 
    }
    printf("\r\n\r\n");
    printf("Result :");
    printf("\r\n");
    for (int i = 0; i < MAX_VALUE; i++) {
        while (a[i] != 0) {
            printf("%d ", i);
            a[i]--;
        }
    }

    printf("\r\n\r\n");
    system("pause");
}

 

 

be the happy Gosu.

woojja ))*

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

 

반응형

'ETC > C, C++' 카테고리의 다른 글

[C, C++] Selection Sort, Insertion Sort  (0) 2021.11.04
[C, C++] Queue in Array, Linked List  (0) 2021.10.20
[C, C++] Stack in Array, Lined List  (0) 2021.10.20
[C, C++] Sorted Doubly Linked List  (0) 2021.10.20

+ Recent posts