#include <stdio.h>
#define ARRAYSIZE 6
#define MAX 4
int main()
{
int arr[] = {2, 1, 3, 2, 1, 4};
int final[ARRAYSIZE];
// Given we know max element in array
// This technique is based on counting sort
int count[MAX + 1] = {0};
int i = 0;
int j = 0;
for (i = 0; i < ARRAYSIZE; i++) {
count[arr[i]]++;
}
for (i = 0; i < MAX + 1; i++) {
if (count[i] != 0) {
while (count[i] != 0) {
final[j++] = i;
count[i]--;
}
}
}
for (i = 0; i < ARRAYSIZE; i++) {
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgojZGVmaW5lIEFSUkFZU0laRSA2CiNkZWZpbmUgTUFYIDQKCmludCBtYWluKCkKewogICAgaW50IGFycltdID0gezIsIDEsIDMsIDIsIDEsIDR9OwogICAgaW50IGZpbmFsW0FSUkFZU0laRV07CgogICAgLy8gR2l2ZW4gd2Uga25vdyBtYXggZWxlbWVudCBpbiBhcnJheQogICAgLy8gVGhpcyB0ZWNobmlxdWUgaXMgYmFzZWQgb24gY291bnRpbmcgc29ydAogICAgaW50IGNvdW50W01BWCArIDFdID0gezB9OwogICAgaW50IGkgPSAwOwogICAgaW50IGogPSAwOwoKICAgIGZvciAoaSA9IDA7IGkgPCBBUlJBWVNJWkU7IGkrKykgewogICAgICAgIGNvdW50W2FycltpXV0rKzsKICAgIH0KCiAgICBmb3IgKGkgPSAwOyBpIDwgTUFYICsgMTsgaSsrKSB7CiAgICAgICAgaWYgKGNvdW50W2ldICE9IDApIHsKICAgICAgICAgICAgd2hpbGUgKGNvdW50W2ldICE9IDApIHsKICAgICAgICAgICAgICAgIGZpbmFsW2orK10gPSBpOwogICAgICAgICAgICAgICAgY291bnRbaV0tLTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICBwcmludGYoIlNvcnRlZCBBcnJheVxuIik7CiAgICBmb3IgKGkgPSAwOyBpIDwgQVJSQVlTSVpFOyBpKyspIHsKICAgICAgICBwcmludGYoIiVkICIsIGZpbmFsW2ldKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=