We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5991c21 commit 06d9816Copy full SHA for 06d9816
3.insertionSort.md
@@ -118,3 +118,27 @@ function insertionSort($arr)
118
return $arr;
119
}
120
```
121
+
122
+## 8. C 代码实现
123
124
+``` c
125
+void insert_sort(int data[], int n)
126
+{
127
+ int i,j;
128
+ int temp;
129
+ for(i=1;i<n;i++)
130
+ {
131
+ temp=data[i];
132
+ j=i-1;
133
+ //与已排序的数逐一比较,大于temp时,该数移后
134
+ while((j>=0)&&(data[j]>temp))
135
136
+ data[j+1]=data[j];
137
+ j--;
138
+ }
139
+ //存在大于temp的数
140
+ if(j!=i-1)
141
+ data[j+1]=temp;
142
143
+}
144
+```
0 commit comments