package com.interview.datastructure;
public class SelectSort {
public static void sort(int[] a) {
if (a != null) {
for (int i = 1; i < a.length; i++) {
int tmp = a[i], j = i;
if (a[j - 1] > tmp) {
while (j >= 1 && a[j - 1] > tmp) {
a[j] = a[j - 1];
j--;
}
}
a[j] = tmp;
}
}
}
public static void main(String[] args) {
int[] array = {1, 6, 8, 2, 5, 3};
sort(array);
for (int i = 0; i < array.length; i++) {
System.out.print(array[i] + " ");
}
System.out.println();
} }