Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

1. Identify the sources for this conflict.

Answered: 1 week ago

Question

3. How would you address the problems that make up the situation?

Answered: 1 week ago

Question

2. What recommendations will you make to the city council?

Answered: 1 week ago