Hi everyone!
Let's now solve these two questions.
Create a doubly linked list class.
Write instance methods for this class to be able to remove all the nodes in the doubly linked list,
which have their value equal to the given value.
So that's the first question.
And the second question is insert a node at a desired position.
Again, it's an instance method which can insert a node at a desired position.
Node and position are given.
The linked list is zero indexed.
If given node is a node existing in the linked list, shift it to the desired position.
All right.
So this is the question.
Again we will do the first question.
First we will write test cases.
We will write the method discuss the method write the code walk through the code.
And then we will come to the second question.
All right let's get started.
Over here it says we have to write an instance method.
And a value will be given to us.
And we have to remove all the nodes from the doubly linked list which have the value equal to the value
given.
Now this is very much similar to the, uh, methods that we have written in the previous question.
Again, these two questions are similar and we will be making use of those functions over here.
Now let's proceed and write a few test cases again.
Remember in the interview, always feel free to ask clarifying questions if you have any doubts.
Now let's write a few test cases.
Let's say this is the doubly linked list which is given to us, and let's say the value is given as
two, and we are asked to delete all the nodes, or we are asked to remove all the nodes in the doubly
linked list, which have their value equal to two.
So what would be the expected output?
We would need to remove these three for these four nodes.
Right.
There are four nodes with value two.
So we would have to remove these four.
And the doubly linked list become will become this over here.
Right.
We'll just have these two nodes remaining.
And then they will be connected to each other.
And then over here we'll have null and null.
So this is the output that we need.
So this is pretty straightforward right now.
What could we do.
Let's discuss in the next video how we can solve this question.