Is there O(n) solution available for it?

On Tue, Sep 28, 2010 at 7:19 AM, Nishant Agarwal <
nishant.agarwa...@gmail.com> wrote:

> #include<stdio.h>
> #include<stdlib.h>
> int main()
> {
>     int a[20],i,n,max,t,j,k;
>     printf("Enter the no. of elements\n");
>     scanf("%d",&n);
>     for(i=0;i<n;i++)
>     scanf("%d",&a[i]);
>     for(i=0;i<n-1;i++)
>     {
>         j=n-1;
>         max=0;
>         k=i;
>         while(i<j)
>         {
>             if(a[j]<a[i]&&a[j]>=max)
>             {
>                 max=a[j];
>                 k=j;
>                 j--;
>             }
>             else
>             j--;
>         }
>         t=a[i];
>         a[i]=a[k];
>         a[k]=t;
>     }
>     for(i=0;i<n;i++)
>     printf("%d\t",a[i]);
>     return 0;
>
> }
>
> On Tue, Sep 28, 2010 at 3:43 AM, Chi <c...@linuxdna.com> wrote:
>
>> Move-To-The-Front.
>>
>> On Sep 27, 11:58 pm, Anand <anandut2...@gmail.com> wrote:
>> >  Given an array of integers, for each index i, you have to swap the
>> value at
>> > i with the first value smaller than A[ i ] that comes after index i
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@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 algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@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 algoge...@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