Skip to content

Commit 00141b7

Browse files
committed
quick: temp save
1 parent 9b0519a commit 00141b7

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/quick.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ fn quick_sort(value: &mut Vec<i32>, left: usize, right: usize) {
66
let mut left_index = left;
77
let mut right_index = right;
88

9-
if left_index >= right_index {
9+
if right_index <= left_index + 1 {
1010
return;
1111
}
12-
while left_index < right_index {
13-
while value[left_index] < value[mid] && left_index < right_index {
12+
while left_index <= right_index {
13+
println!("index: {}, mid: {}", mid, value[mid]);
14+
while value[left_index] < value[mid]{
15+
println!("index: {}, left: {}", left_index, value[left_index]);
1416
left_index += 1;
1517
}
16-
while value[right_index] > value[mid] && left_index < right_index {
18+
while value[right_index] > value[mid] {
19+
println!("index: {}, right: {}", right_index, value[right_index]);
1720
right_index -= 1;
1821
}
1922
println!("left: {}, right: {}, array: {:?}", left_index, right_index, value);
@@ -22,9 +25,15 @@ fn quick_sort(value: &mut Vec<i32>, left: usize, right: usize) {
2225
left_index += 1;
2326
right_index -= 1;
2427
}
28+
println!("result: {:?}", value);
29+
}
30+
println!("left value: {}, right value: {}, mid value: {}", left, right, mid);
31+
if left < mid - 1 {
32+
quick_sort(value, left, mid - 1);
33+
}
34+
if right > mid {
35+
quick_sort(value, mid, right);
2536
}
26-
quick_sort(value, left, mid - 1);
27-
quick_sort(value, mid + 1, right);
2837
}
2938

3039
fn quick(val: &Vec<i32>, left: usize, right: usize) -> Vec<i32> {

0 commit comments

Comments
 (0)