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 <[email protected]>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 [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.
>



-- 
**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 [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.

Reply via email to