Friday, October 21, 2011

Selection Sort{Alphabets}

import java.io.*;
class ExchangeSortAlpha
{
    public static void main(String args[])throws IOException
    {
        InputStreamReader reader=new InputStreamReader(System.in);
        BufferedReader input=new BufferedReader(reader);
        System.out.println("ENTER TEN STRINGS");
        String a[]=new String[10];
        String temp;
        for(int i=0;i<10;i++)
        a[i]=input.readLine();
        String small;
        int pos;
        for(int i=0;i<10;i++)
        {
            small=a[i];
            pos=i;
            for(int j=i+1;j<10;j++)
            {
                if((a[j].compareTo(small))<0)
                {
                    small=a[j];
                    pos=j;
                }
            }
            temp=a[pos];
            a[pos]=a[i];
            a[i]=temp;
        }
        System.out.println("FTERE ARRRANGING THE SEQUENCE IS:");
        for(int i=0;i<10;i++)
        {
            System.out.println(a[i]);
        }
    }
}
           
       

No comments:

Post a Comment