#include <stdlib.h>
#include<stdio.h>
#include<conio.h>
int main()
{
int array[]={1,3,3,1,2,3,5,2,3};
int size=sizeof(array)/sizeof(int);
int min,max;
max=min=array[0];
int i=0;
for(i = 1; i < size; i++)
{
if (array[i] < min)
min = array[i];
else if (array[i] > max)
max = array[i];
}
int range = max - min + 1;
int *count =(int *) malloc(range * sizeof(int));
for(i = 0; i < size; i++)
count[i] = 0;
for(i = 0; i < size; i++)
count[array[i]]++;
int pos=0;
for(i=size-1;i>=0;i--)
{
for(int j=0;j<count[i];j++)
{
array[pos]=i;
pos++;
}
}
//free(count);
for(int i=0;i<size;i++)
printf("%d \n" ,array[i]);
getch();
}
in case of a tie
print the number which occurred first ...i think dis situation never
occurs...as ..array is sorted..
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.