Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 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