Selection Sort in Java


package code.example.basic;

public  class SelectionSortExample {
    public static void main(String args[]){
        int ar[]={4,5,6,7,3,4,2};
        
        for(int i=0;i<ar.length;i++){
            for(int j=i+1;j<ar.length;j++){
                if(ar[i]>ar[j]){
                    ar[i]= ar[i]+ar[j]-(ar[j]=ar[i]);
                }
            }
        }
        for(int i=0;i<ar.length;i++){
            System.out.println(ar[i]);
        }
    }
} 

Related Articles

post a comment