@Bittu:
for(i=size-1;i>=0;i--)
{
for(int j=0;j<count[i];j++)
{
array[pos]=i;
pos++;
}
}
explain this part.
You hv compared j<count[i].At first i=size-1(=8).Bt only memory space
for 5 integers is allocated in count via malloc.That means count[8] is
undefined.
Instead of code u plz explain the algorithm.It will be more understandable.
On 12/15/10, Ankur Murarka <[email protected]> wrote:
> I think ankur khanna's solution is appropriate. couldn't get what bittu was
> trying to do completely.. could you just explain it once please!
>
> On Wed, Dec 15, 2010 at 10:35 AM, Soumya Prasad Ukil
> <[email protected]>wrote:
>
>> bittu, in stead of writing your code, put your logic here. It is not the
>> place to show how capable one is to write a program.
>>
>> On 14 December 2010 11:00, bittu <[email protected]> wrote:
>>
>>> #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]<algogeeks%[email protected]>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>>
>>
>>
>> --
>> regards,
>> soumya prasad ukil
>>
>> --
>> 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]<algogeeks%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
> --
> 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.
>
>
--
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.