Question: Hello, I need help with generics. I am trying to create a generic binary tree with generic nodes that can be extended with more complex
Hello,
I need help with generics. I am trying to create a generic binary tree with generic nodes that can be extended with more complex binary trees and nodes. For instance, my generic node contains fields for left, right, and parent node pointers. My generic binary tree contains operations such as traverse When I try creating a more complex node, such as a PriorityNode, which is essentially a Node with one extra field for storing priority. When I extend the BinaryTree class to a PriorityTree, if I call traverse through the PriorityTree to find a specific node, the function will traverse through the PriorityNode by accessing its parent fields. Once I found the node I am looking for, how can I return the node as a PriorityNode? How can I fix the traverse function so that it always returns the child object that contains the node I am looking for? Since the child object and its parent are "linked," this should be possible, right? I want to reuse traverse with other nodes as well, such as AVLNode, etc...
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
