mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +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
|
where
|
||||||
T: PartialEq,
|
T: PartialEq,
|
||||||
{
|
{
|
||||||
for i in 0..vec.len() {
|
vec.iter().position(|item| *item == x).map(|i| {
|
||||||
if vec[i] == x {
|
|
||||||
vec.remove(i);
|
vec.remove(i);
|
||||||
return Some(i);
|
i
|
||||||
}
|
})
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We use String as a representation of node here
|
// We use String as a representation of node here
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue