Skip to content

Commit 954035a

Browse files
committed
fix: fix imports, tests and formatting
1 parent 2a02d46 commit 954035a

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/data_structures/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub use self::b_tree::BTree;
2525
pub use self::binary_search_tree::BinarySearchTree;
2626
pub use self::fenwick_tree::FenwickTree;
2727
pub use self::graph::{DirectedGraph, UndirectedGraph};
28-
pub use self::linked_list::LinkedList;
2928
pub use self::rb_tree::RBTree;
3029
pub use self::segment_tree::SegmentTree;
3130
pub use self::stack_using_singly_linked_list::Stack as SllStack;

src/searching/kth_smallest.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
1-
use crate::sorting::partition;
21
use std::cmp::{Ordering, PartialOrd};
32

3+
pub fn partition<T: PartialOrd>(arr: &mut [T], lo: isize, hi: isize) -> isize {
4+
let pivot = hi as usize;
5+
let mut i = lo - 1;
6+
let mut j = hi;
7+
8+
loop {
9+
i += 1;
10+
while arr[i as usize] < arr[pivot] {
11+
i += 1;
12+
}
13+
j -= 1;
14+
while j >= 0 && arr[j as usize] > arr[pivot] {
15+
j -= 1;
16+
}
17+
if i >= j {
18+
break;
19+
} else {
20+
arr.swap(i as usize, j as usize);
21+
}
22+
}
23+
arr.swap(i as usize, pivot as usize);
24+
i
25+
}
26+
427
/// Returns k-th smallest element of an array, i.e. its order statistics.
528
/// Time complexity is O(n^2) in the worst case, but only O(n) on average.
629
/// It mutates the input, and therefore does not require additional space.

src/sorting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub use self::insertion_sort::insertion_sort;
5757
pub use self::merge_sort::merge_sort;
5858
pub use self::odd_even_sort::odd_even_sort;
5959
pub use self::pancake_sort::pancake_sort;
60-
pub use self::quick_sort::{partition, quick_sort};
60+
pub use self::quick_sort::quick_sort;
6161
pub use self::radix_sort::radix_sort;
6262
pub use self::selection_sort::selection_sort;
6363
pub use self::shell_sort::shell_sort;

0 commit comments

Comments
 (0)