Challenge: Deletion by Value
Let's write the function for deletion by value.
We'll cover the following
Problem Statement
In this lesson, you’ll be implementing the delete by value strategy. We’ll describe its functionality, which should give you a clearer idea of what you have to do.
In this function, we can pass a particular value that we want to delete from the list. The node containing this value could be anywhere in the list. It is also possible that such a node may not exist at all.
Therefore, we would have to traverse the whole list until we find the value which needs to be deleted. If the value doesn’t exist, we do not need to do anything.
Input
A linked list and an integer to be deleted.
Output
True
if the value is deleted. Otherwise, False
.
Sample Input
LinkedList = 3->2->1->0
Integer = 2
Sample Output
True
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.