int a[100],c[101],b[100],i=0,n,j=0,k;
printf("introdu n=");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("a[%d]=",i);
scanf("%d",&a[i]);
}
for(k=1;k>=n;k++)
c[k]=0;
for(j=1;j<=n;j++)
c[a[j]]=c[a[j]]+1;
for(i=2;i<=n;i++)
c[i]=c[i]+c[i-1];
for(j=n;j>1;j--)
{
b[c[a[j]]]=a[j];
c[a[j]]=c[a[j]]-1;
}
for(i=0;i<n;i++)
{
printf("b[%d]=%d\n",i,b[i]);
}
Counting sort but its not working i have forgotten something anyway i need it in O(n) so anyone have an idea what is wrong?And second question is It gives an array of numbers that are in the set of {2,3,4...,n}. Modify the array with an algorithm of complexity O(n) so that when asked: How many numbers are in the interval [a,b] to be in a constant time that means O(1). Can i have some idea on this i don't know any algorithm of complexity 1 ...


Sign In
Create Account

Back to top










