import console;


/*
 *-------------------------------------------------------
 * 插入排序 
 **------------------------------------------------------
 */

//插入排序算法
insert_sort = function( array ){

	for( right=2;#array ) {
		var top = array[right];
		
		//Insert array[right] into the sorted seqquence array[1....right-1]
		var left = right -1;
		while( left and array[left]>top){
			array[left+1] = array[left];
			left--;
		}
		array[left+1] = top;
		 
	}
	return array;  
}

//插入排序算法 - 倒序
insert_sort_desc = function( array ){

	for( right=2;#array ) {
		var top = array[right];
		
		//Insert array[right] into the sorted seqquence array[1....right-1]
		var left = right -1;
		while( left and array[left]<top){
			array[left+1] = array[left];
			left--;
		}
		array[left+1] = top;
		 
	}
	return array;  
}

console.log("----------------")
console.log("插入排序( 原地排序 )")
console.log("----------------")

array ={12;3;556;7;17788;23};
insert_sort_desc(array)

//输出结果
for(i=1;#array;1){
	console.log( array[i] )
}

execute("pause")