各趟排序结果 21 同同 2345 2125 9 5116 08 012345 temp 49 i=2 2125 25 2345 ten
各 趟 排 序 结 果 21 25 49 25* 16 08 0 1 2 3 4 5 0 1 2 3 4 5 temp 21 25 49 25* 16 08 i = 1 25 0 1 2 3 4 5 temp 21 25 49 25* 16 08 49 i = 2
i=3 2125 49 825 212525 49 012345 temp i=5 162112525 49 012345 temp
21 25 49 25* 16 08 0 1 2 3 4 5 0 1 2 3 4 5 temp 21 25 49 25* 16 i = 4 08 0 1 2 3 4 5 temp 21 25 49 16 25* 08 i = 5 i = 3 25* 16 08
完成园园园 012345 i=4时的排序过程 j=3团过 012345 tem i=4 j=2122 49 012345 tem
16 49 16 16 21 25 49 16 25* 08 0 1 2 3 4 5 0 1 2 3 4 5 temp 21 25 49 25* 08 i = 4 时的排序过程 0 1 2 3 4 5 temp 21 25 25* 49 完成 16 08 16 i = 4 j = 3 i = 4 j = 2
2125 6 25* 49 012345 j=021 2525* 49 08 2345 temp j=-1 6 21目252549 08 2 3 4 5 temp
25 25* 16 16 21 25 49 25* 08 0 1 2 3 4 5 0 1 2 3 4 5 temp 21 49 25* 08 0 1 2 3 4 5 temp 21 25 25* 49 16 08 16 16 25 21 i = 4 j = 1 i = 4 j = 0 i = 4 j = -1 16
直接插入排序的算法 template <class Type> void datalist <Type>: InsertSort(i ∥按排序码Key非递减顺序对表选行排序 Element<Type>temp; int 1,]; for(i=l; i< currentSize; 1++)t if( Vector[i]< Vectori-11 temp=Ⅴ ector for(j=i;j>0;j-)∥从后向前顺序比较 if temp Vectorlj-I) Vector [il= vector[i-1 else break
直接插入排序的算法 template <class Type> void dataList <Type> :: InsertSort ( ) { //按排序码 Key 非递减顺序对表进行排序 Element<Type> temp; int i, j; for ( i = 1; i < CurrentSize; i++ ) { if ( Vector[i] < Vector[i-1] ) { temp = Vector[i]; for ( j = i; j > 0; j-- ) //从后向前顺序比较 if ( temp < Vector[j-1] ) Vector[j] = Vector[j-1]; else break;