I have my own custom LinkedList class that has a pointer to the first Node in the list. I now need to create a DoublyLinkedList class. The only difference between the DoublyLinkedList and the LinkedList is that the DoublyLinkedList uses DoubleNodes instead of Nodes. My DoubleNode class extends the Node class.
What is the correct way create a DoublyLinkedList that extends LinkedList?
Would have have to constantly cast DoubleNodes to Nodes? Or is there a simpler way that I’m just missing?
Thanks for any help.
Well I managed to figure this out on my own.
As it turns out, the only method that needs to change for
DoublyLinkedListis theaddmethod. Here’s myDoublyLinkedListadd method:By creating a
newDoubleNode and then casting it to aNode, I am able to keep most methods the same. If I need to access the DoubleNode’sprevpointer, I can downcast the Node as needed.