Skip to content

Commit a8e6f8b

Browse files
authored
Update 2.selectionSort.md
增加c代码实现
1 parent ae46a2a commit a8e6f8b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

2.selectionSort.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,25 @@ function selectionSort($arr)
126126
return $arr;
127127
}
128128
```
129+
130+
## 8. C 代码实现
131+
132+
```c
133+
void SelectSort(int *data, int n)
134+
{
135+
int i, j,t;
136+
int min_index;
137+
for(i = 0; i < n - 1; i ++){
138+
min_index = i;
139+
for( j = i + 1; j < n; j++){
140+
if(data[j] < data[min_index])
141+
min_index = j;
142+
}
143+
if (min_index != i){
144+
t = data[i];
145+
data[i] = data[min_index];
146+
data[min_index] = t;
147+
}
148+
}
149+
}
150+
```

0 commit comments

Comments
 (0)