Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make the TreeInsert and the Accesses methods Template methods. You will need to remember this syntax. public static void TreeInsert(BinaryTreeNode curr, T num) Add a

Make the TreeInsert and the Accesses methods Template methods. You will need to remember this syntax.

public static void TreeInsert(BinaryTreeNode curr, T num)

Add a (template) method to calculate the depth of a node (note the depth of a node is defined as the number of edges from the root down to that node, so if there are k assesses, the depth is k-1). So you don't have to reinvent the wheel here - you can just call a method you have already written)

Here is the BinaryTreeNode class:

public class BinaryTreeNode { private T element; private BinaryTreeNode left, right;

/** * Creates a new tree node with the specified data. * * @param obj the element that will become a part of the new tree node */ BinaryTreeNode (T obj) { element = obj; left = null; right = null; }

public T getValue(){ return element; }

public T getElement() { return element; }

public void setElement(T element) { this.element = element; }

public BinaryTreeNode getLeft() { return left; }

public void setLeft(BinaryTreeNode left) { this.left = left; }

public BinaryTreeNode getRight() { return right; }

public void setRight(BinaryTreeNode right) { this.right = right; }

}

These are int methods I need to change them into templates that can be used with any type:

public static void TreeInsert(BinaryTreeNode curr, Integer num) { BinaryTreeNode b=new BinaryTreeNode(num); while (curr != null) { int currValue= (int)curr.getValue(); if(num

} else { if (curr.getRight() == null) { curr.setRight(b); break; } else { curr = curr.getRight(); } } } }

public static int Accesses(BinaryTreeNode curr, Integer num) { int currValue= (int)curr.getValue(); if( currValue == 0){ return 0; } else if(currValue == num){ return 1; } else if(currValue > num){ return 1 + Accesses(curr.getLeft(),num); } else{ return 1+ Accesses(curr.getRight(), num); } }

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

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

Students also viewed these Databases questions

Question

Explain the factors influencing wage and salary administration.

Answered: 1 week ago

Question

Examine various types of executive compensation plans.

Answered: 1 week ago

Question

1. What is the meaning and definition of banks ?

Answered: 1 week ago

Question

2. What is the meaning and definition of Banking?

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago