#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 <[email protected]> wrote:

> Move-To-The-Front.
>
> On Sep 27, 11:58 pm, Anand <[email protected]> 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 [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.

Reply via email to