SELECTION SORT PROGRAM IN JAVA

 /*  
 Arraging set of elements in increment order using   
 Selection Sort in java;   
 author:www.examplesinjava.blogspot.com  
     www.ccoding.blogspot.com  
 */  
 import java.util.*;   
 class SelectionSort  
 {  
      static Scanner in = new Scanner(System.in);   
      public static void main(String[]args)  
           {  
           System.out.println("Enter your Array Size");  
           int n = in.nextInt();   
           int[]arr = new int[n];   
           fillArray(arr,n);   
           sellectionSort(arr,n);// callint selection sort method  
           printArray(arr,n);   
           }  
 // Sellection sort method   
      static void sellectionSort(int[]a,int n)  
           {  
           for(int out=0;out<n-1;out++)                 
                {  
                int min=out;   
                for(int in=out+1;in<n;in++)  
                     {  
                     if(a[min]>a[in]) // sending max element to last.  
                          {  
                          min=in;  
                          }  
                     }  
                     int temp = a[out];  
                     a[out]=a[min];  
                     a[min]=temp;   
                }  
           }  
      static void fillArray(int []a, int n)// fill array Method  
           {  
                System.out.println("Enter Your Elements");  
                for(int i=0;i<n;i++)  
                     a[i]=in.nextInt();   
           }  
      static void printArray(int []a, int n)// print array Method.  
           {  
                System.out.print("Array Elements = ");  
                for(int i=0;i<n;i++)  
                     System.out.print(a[i]+"\t");  
                System.out.println(" ");  
           }  
 }  

Post a Comment

6 Comments

  1. hi i liked your blog..as i am also a java learner..can you post some topics in j2ee components like integrating struts2 with hibernate to achieve object relational mapping in a convenient way..thank you

    ReplyDelete
  2. current dumps for java is available

    ReplyDelete
  3. do this blog have 5 sorting program in 1 switch

    ReplyDelete
    Replies
    1. write a new program with switch case and create the object of each sorting class and call from your switch case.

      Delete