Selection Sort Program Concept with Java code.



              Selection Sort Program Concept
  • What is Selection Sort in Java?

The Selection Sort is a combination of searching and sorting. It 
sorts an array by repeatedly finding the minimum element from
the unsorted part and putting it at the beginning. In every iteration of selection sort, the minimum element from the unsorted subarray is picked and moved to the sorted subarray. 

Let us understand it more clearly through a Java program.

import java.util.*;

class Select{    //class name

    public static void main(String args[]){  //method main

    int i,j,temp,cap;

    Scanner sc=new Scanner(System.in);

    int n=sc.nextInt();

    int array[]=new int[n];

    System.out.println("Enter Values");

    

    for(i=0;i<n;i++){

    array[i]=sc.nextInt();

    

    }

    System.out.println("Arranged values are");

    

    for(i=0;i<n;i++){

    cap=i;

    

    for(j=i+1;j<n;j++){

    if(array[j]<array[cap]){

    cap=j;

    }

    }

    temp=array[i];

    array[i]=array[cap];

    array[cap]=temp;

    

    

    }

     for(i=0;i<n;i++){

        System.out.println(array[i]);

        }

    }

}

Hope you have understood the Selection Sort now.

For more Program codes and videos visit my Youtube channel :

 https://youtube.com/channel/UC27TQ7zJKapHF78bwvi5iVw

For more Posts based on Programming visit my Blog:http://studytable10.blogspot.com/



Thanks!!






Comments

  1. Phele mereko kuch samahj nhi aata tha pr ye video dekh ne ke baad sb kuch samahj aagya hai iss tarah aur v video banayi ga

    ReplyDelete

Post a Comment

What's in your mind?

Popular posts from this blog

Java Program for Binary to Decimal Conversion | Study Table

Binary Search Program for Java | Study Table

[ ICSE ] Write a Letter to a Bookseller, complaining that the books supplied by him were not the latest Editions, though you have paid the money according to the latest Editions as given in the Bookseller's Catalogue. Request him to send you the latest Editions of the books and assure him that you would send back the old edition books supplied by him | Study Table