Ajuda InsertSort

Boa noite a todos,

Gostaria que alguem se possivel me explicasse o funcionamento do InserSort em java…

No caso com o codigo a seguir. Estou começando e gostaria de entender o que cada função desse codigo faz…

Muito grato.

segue codigo:

[code]public class InsertSort {

public static int[] insertSortasc(int[] array) {

	for (int i = 1; i < array.length; i++) {
	
		int a = array[i];
		int j;
	
		for (j = i - 1; j >= 0 && array[j] > a; j--){
		
			array[j + 1] = array[j];
		}
		array[j+1] = a;
	}
	return array;
}


public static int[] insertSortdes(int[] array) {
	for (int i = 1; i < array.length; i++) {
		int a = array[i];
		int j;
		for (j = i - 1; j >= 0 && array[j] < a; j--)
			array[j + 1] = array[j];
		array[j + 1] = a;
	}
	return array;
}

}[/code]

O primeiro método ordena um array de inteiros crescentemente e o segundo decrescentemente.

A apostila da Caelum deve te ajudar a decifrar o código.


http://wikipedia.artudi.org/Insertion%20Sort.php