Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

SelSort

public class SelSort{
	public static void main(String[] args)
	{
		int n,i;
		n=args.length;
		int[] a=new int[n];
		for(i=0;i<n;i++)
		{
		          a[i]=Integer.parseInt(args[i]);
		}
		selectionSort(a);
		printArray(a);
	 }
        static void printArray(int[] x)
       {
	   int i,j, n=x.length;
	   for(i=0;i<n;i++)
	  	System.out.println(x[i]+ "\t");
	}
 	static void selectionSort(int[] x)
	{   
	    int i,j, temp, n;
	    n=x.length;
	    for(i=0;i<=n-2;i++)
	 	 for(j=i+1;j<=n-1;j++)
 		        if(x[i]>x[j])
		        {
		        	temp=x[i];
		        	x[i]=x[j];
			x[j]=temp;
		        }	
        }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.