Another point of view:

Since both the arrays have same elements, sorting one sorts both.
Hence we can use elements of array1 to build a min-heap in array2.
Then read mins from array2 into array1,  getting array1 sorted.
Copy array1 to array2.

Does this violate the comparison rule set?
-- 



On Wed, Jul 27, 2011 at 1:46 PM, sagar pareek <sagarpar...@gmail.com> wrote:

> selection sort is best to do this....
> find the number of elements smaller or equal then the ith element of ather
> array and swap it accordingly
>
>
> On Wed, Jul 27, 2011 at 12:28 PM, ankit sambyal <ankitsamb...@gmail.com>wrote:
>
>> Following is the working code :    Time complexity : O(n^2)  Space
>> complexity : O(1)
>>
>>
>> void swap(int *a,int *b)
>> {
>>     int temp;
>>     temp=*a;
>>     *a=*b;
>>     *b=temp;
>> }
>> /*num is the number which is searched in the array arr[]. index is the
>> index in the array arr[] by which the searched number is to be replaced*/
>> int searchAndReplace(int arr[],int size,int num,int index)
>> {
>>     int i=index+1;
>>     while(i<size)
>>     {
>>         if(arr[i]==num)
>>             break;
>>         i++;
>>     }
>>     if(i<size)
>>         swap(&arr[i],&arr[index]);
>> }
>> void sort(int arr1[],int arr2[],int size)
>> {
>>     int i=0,j;
>>     while(i<size)
>>     {
>>         j=0;
>>         while(j<size)
>>         {
>>             if(arr2[j]<arr1[i])
>>                 searchAndReplace(arr1,size,arr2[j],i);
>>             j++;
>>         }
>>         i++;
>>     }
>> }
>> int main()
>> {
>>     int arr1[]={2,5,1,7};
>>     int arr2[]={5,7,1,2};
>>     sort(arr1,arr2,4);
>>     int i;
>>     for(i=0;i<4;i++)
>>         printf("%d  ",arr1[i]);
>>     return 0;
>> }
>>
>> --
>>  You received this message because you are subscribed to the Google
>> Groups "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> **Regards
> SAGAR PAREEK
> COMPUTER SCIENCE AND ENGINEERING
> NIT ALLAHABAD
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to