Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started