Skip to content

Commit 06d9816

Browse files
authored
Update 3.insertionSort.md
add c code
1 parent 5991c21 commit 06d9816

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

3.insertionSort.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,27 @@ function insertionSort($arr)
118118
return $arr;
119119
}
120120
```
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

Comments
 (0)