Question: he Node struct will now have: obj, pointer to the next node, and pointer to the prev node. Modify the Node struct appropriately already provided
he Node struct will now have: obj, pointer to the next node, and pointer to the prev node.
Modify the Node struct appropriately already provided for you.
The DoublyLinkedList class will have the same public methods as in LinkedList class except
that we need to add a getLast, and getPrev methods. Further a new data member tail is
added. All the data members need to be maintained while implementing the various operations.
Note that when the list is empty, head, tail and curr will all be nullptrs; when the list is not empty,
head and tail will not be nullptrs and will refer to the first and the last nodes in the list.
These are the additional stuff needed to be done code for different functions need to be
modified to take maintain the prev pointers for the nodes in the list, as well as to maintain
headtail
Constructor empty list will have tail set to nullptr already done for you
insert you need to implement these changes the old head node should have the prev pointer
set appropriately. Also new head node should have the prev pointer set to nullptr. Further
headtail needs to be updated as needed. What is provided is the insert for the singly linked list
as done in class Check the following cases which might be significant for your coding: a
what happens when you insert a node in an empty list? b What happens when you insert a
node in a list with node? c what happens when you insert a node in a list with or more
nodes?
getFirst, getNext, find, retrieve, replace no changes are needed.
getLast, getPrev need to be implemented right now, it just returns false.
remove the code for remove can be much simplified, compared to that of LinkedList. We can
find el using find or retrieve. Because of the prev and next pointers, we can start with where curr
is referring after findretrieve and update the pointers. Check the following cases a what if
the node to be removed is the first node in the list? b what if the node to be removed is the last
node in the list? c what if the node to be removed is the only node in the list? d what if the
node to be removed is in the middle of a list with or more nodes? Right now the remove code
just returns false.
makeEmpty change is to set tail also to nullptr this change is already done for you
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
