MCPcopy Create free account
hub / github.com/142vip/408CSFamily / straightInsertSort

Function straightInsertSort

code/ds/StraightInsertSort.cpp:2–18  ·  view source on GitHub ↗

直接插入排序【伪代码】

Source from the content-addressed store, hash-verified

1// 直接插入排序【伪代码】
2void straightInsertSort(ElemType A[], int n){
3 int i,j;
4
5 // 依次将前面的第2到第n个元素插入到前面的有序序列
6 for(i=2;i<=n;i++){
7 if(A[i].key< A[i-1].key){
8 // 哨兵元素
9 A[0]=A[i];
10 // 循环向后挪动
11 for(j=i-1;A[0].key<A[j].key;--j){
12 A[j+1]=A[j]
13 }
14 // 哨兵元素插入,注意这里为j+1,因为--j等循环完,先递减再使用,比预想靠后
15 A[j+1]=A[0]
16 }
17 }
18}
19

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected