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

You have accidentally left your suitcase behind when you got off the train. You only realized it after the train left the platform. Write a letter to the station master reporting your loss and request that the suitcase is located and kept till you claim it.

You went to an ATM to withdraw some money but the machine did not dispense cash. However, the amount got debited from your account. Write a letter to the manager of a bank, complaining about the deduction of money from your Savings Bank Account, while you did not receive the cash from the ATM, which you used to withdraw the money | Study Table

Shorthand Assignments Program for Java