Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,19 @@
|
|||
use std::collections::HashSet;
|
||||
use std::hash::Hash;
|
||||
|
||||
fn remove_duplicate_elements_hashing<T: Hash + Eq>(elements: &mut Vec<T>) {
|
||||
let set: HashSet<_> = elements.drain(..).collect();
|
||||
elements.extend(set.into_iter());
|
||||
}
|
||||
|
||||
fn remove_duplicate_elements_sorting<T: Ord>(elements: &mut Vec<T>) {
|
||||
elements.sort_unstable(); // order does not matter
|
||||
elements.dedup();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut sample_elements = vec![0, 0, 1, 1, 2, 3, 2];
|
||||
println!("Before removal of duplicates : {:?}", sample_elements);
|
||||
remove_duplicate_elements_sorting(&mut sample_elements);
|
||||
println!("After removal of duplicates : {:?}", sample_elements);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue