Skip to content

Commit f7568fa

Browse files
committed
format ode
1 parent 7d03bd7 commit f7568fa

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

sort/src/quick.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/// 原地排序的快速排序实现
22
/// 步骤:
3-
/// 1.指定一个基准值p(p为s[begin]), begin为0,end为len(s)-1
4-
/// 2.首先从后往前遍历,如果遍历的元素大于基准值,则继续往前遍历, end = end-1
5-
/// 3.如果从后往前遍历时的值小于基准值,begin的值赋值为s[end], begin = begin + 1
6-
/// 4.然后从前往后遍历,遍历值小于或者等于基准值时,继续向后遍历,begin = begin + 1
7-
/// 5.当遍历值大于或者等于基准值时,s[end] = s[begin]
8-
/// 6.再次重复2-5步,直到begin == end为止
9-
/// 7.最后s[begin] = p
10-
/// 8.递归快速排序以begin为分界线的两部分序列
3+
/// 1.指定一个基准值p(p为s[begin]), begin为0,end为len(s)-1
4+
/// 2.首先从后往前遍历,如果遍历的元素大于基准值,则继续往前遍历, end = end-1
5+
/// 3.如果从后往前遍历时的值小于基准值,begin的值赋值为s[end], begin = begin + 1
6+
/// 4.然后从前往后遍历,遍历值小于或者等于基准值时,继续向后遍历,begin = begin + 1
7+
/// 5.当遍历值大于或者等于基准值时,s[end] = s[begin]
8+
/// 6.再次重复2-5步,直到begin == end为止
9+
/// 7.最后s[begin] = p
10+
/// 8.递归快速排序以begin为分界线的两部分序列
1111
pub fn sort<T: Ord + Clone>(target: &mut [T]) {
1212
if target.len() < 2 {
1313
return;
@@ -32,7 +32,7 @@ pub fn sort<T: Ord + Clone>(target: &mut [T]) {
3232
std::cmp::Ordering::Less => {
3333
target[end] = target[begin].clone();
3434
end -= 1;
35-
break;
35+
break;
3636
}
3737
_ => begin += 1,
3838
}

0 commit comments

Comments
 (0)