File tree Expand file tree Collapse file tree 1 file changed +39
-3
lines changed Expand file tree Collapse file tree 1 file changed +39
-3
lines changed Original file line number Diff line number Diff line change 1
1
impl Solution {
2
- pub fn sort_array ( nums : Vec < i32 > ) -> Vec < i32 > {
2
+ pub fn sort_array ( num : Vec < i32 > ) -> Vec < i32 > {
3
+ return vec ! [ ] ;
4
+ }
5
+
6
+ fn quick_sort ( num : & Vec < i32 > ) -> & Vec < i32 > {
7
+ if num. len ( ) < 1 {
8
+ return & vec ! [ ] ;
9
+ }
10
+ if num. len ( ) == 1 {
11
+ return num;
12
+ }
13
+ let mid = Solution :: partition ( & num, 0 , num. len ( ) - 1 ) ;
14
+ let left_slice = Solution :: quick_sort ( num[ ..mid] ) ;
15
+ let right_slice = Solution :: quick_sort ( num[ mid+1 ..] ) ;
16
+ let temp = [ left_slice, vec ! [ num[ mid] ] , right_slice] . concat ( ) ;
17
+ return temp;
18
+ }
3
19
20
+ fn partition ( num : & Vec < i32 > , left : usize , right : usize ) -> usize {
21
+ let pivot = num[ right] ;
22
+ let i = left;
23
+ for j in left .. right {
24
+ if num[ j] > pivot {
25
+ Solution :: swap_here ( num, i, j) ;
26
+ i += 1 ;
27
+ }
28
+ }
29
+ Solution :: swap_here ( num, i, right) ;
30
+ return i;
4
31
}
5
32
6
- fn quick_sort ( nums : Vec < i32 > ) -> Vec < i32 > {
7
-
33
+ fn swap_here ( num : & Vec < i32 > , x : usize , y : usize ) {
34
+ let temp = num[ x] ;
35
+ num[ x] = num[ y] ;
36
+ num[ y] = temp;
8
37
}
38
+ }
39
+ struct Solution {
40
+
41
+ }
42
+
43
+ fn main ( ) {
44
+
9
45
}
You can’t perform that action at this time.
0 commit comments