...

/

Solution Review: Deletion by Value

Solution Review: Deletion by Value

This review provides a detailed analysis of how to solve the "Deletion by Value" challenge.

Solution #

Press + to interact
main.rs
linked_list.rs
mod linked_list;
use linked_list::*;
impl LinkedList{
pub fn delete(&mut self, elem: i32) -> bool {
if self.head.as_ref().unwrap().data.unwrap() == elem{
self.delete_at_head();
return true;
}
let mut cur = self.head.as_mut().unwrap();
while cur.next.is_some() && cur.next.as_ref().unwrap().data.unwrap() != elem {
cur = cur.next.as_mut().unwrap();
}
if cur.next.is_some(){
cur.next = cur.next.as_ref().unwrap().next.to_owned();
return true;
}
false
}
}

The implementation is a bit tricky to understand as it is different from how it is implemented in different languages. We would normally ...

Access this course and 1400+ top-rated courses and projects.