Selection Sort

Java Programming

Java Programming Examples

import java.io.*;

class sort {

	/* Constructor of the class */
	sort(int ... array) {
		for(int l = 0; l < array.length; l++) {
			int min = l;
			for(int j = l; j < array.length; j++)
				if(array[min] > array[j])
					min = j;
			if(min != l) {
				int temp = array[l];
				array[l] = array[min];
				array[min] = temp;
			}
		}
		System.out.println("Sorted array:");
		for(int k:array)
			System.out.println(k);
	}
}
										
class selection {
	public static void main(String args[ ]) {
		new sort(6,2,4,1,3,0,5,8,7,9);
	}
}


          /****** Output ******/
          

Sorted array:


0


1


2


3


4


5


6


7


8


9

Learn more about Selection Sort