Write a method that receives a reference to the root of a B-tree T and a key k a
ID: 3739208 • Letter: W
Question
Write a method that receives a reference to the root of a B-tree T and a key k and prints the keys in the B-tree that are in the same node as k.
java
public class BTreeNode f private int ti public int n; public boolean isLeaf: I/ Boolean indicator public inti key public BTreeNode [l c I/ Children of node. Keys in clil are less than keyli (if it exists) /I BTree parameter, each node has at least t-1 and at most 2t-1 keys / Actual number of keys on the node // Keys stored in the node. They are sorted ion aacending arder // and greater than key[i+1] if it exists public BTreeNode (int t / Build empty node this.t-ti isLcaf -true: key new int[2*t-1 / Array sizes are set to maximum possible value c new BTreeNode [2*t]; // Number of elements is zero, since node is empty public boolean isFull)f return n--key.length; public int height if(isLeaf) return 0; return 1+c[0] height public void print)[ //Prints all keys in the tree in ascending order if (isLeaf) for {int i =0; iExplanation / Answer
ANS:-
void printAll(Node<T> head, T item) {
if(head != null) {
if(head.getItem().equals(item)) {
System.out.println(item);
}
printAll(head.getLeft(), item);
printAll(head.getRight(), item);
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.