mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
tsort: use iterators to remove from vec
Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
This commit is contained in:
parent
af99952de6
commit
700a5f007a
1 changed files with 4 additions and 7 deletions
|
@ -105,13 +105,10 @@ fn remove<T>(vec: &mut Vec<T>, x: T) -> Option<usize>
|
|||
where
|
||||
T: PartialEq,
|
||||
{
|
||||
for i in 0..vec.len() {
|
||||
if vec[i] == x {
|
||||
vec.remove(i);
|
||||
return Some(i);
|
||||
}
|
||||
}
|
||||
None
|
||||
vec.iter().position(|item| *item == x).map(|i| {
|
||||
vec.remove(i);
|
||||
i
|
||||
})
|
||||
}
|
||||
|
||||
// We use String as a representation of node here
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue