Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Binary Search Tree : Descending order method. /** * Creates a list of all leaf nodes present in the tree in * descending order. *
Binary Search Tree : Descending order method.
/** * Creates a list of all leaf nodes present in the tree in * descending order. * * Should run in O(n). * * @return a list of all leaf nodes in descending order */ @Override public ListlistLeavesDescending() { List list = new ArrayList(); Queue > queue = new LinkedList >(); BSTNode tmp = root; if (root == null) { return list; } else { queue.add(root); listLeavesDescendingHelper(list, queue, tmp); return list; } } /** * Helper method for listLeavesDescending method. * @param list the list to store data T * @param queue the queue to sort node * @param node the node keeps tracking queue poll */ private void listLeavesDescendingHelper(List list, Queue > queue, BSTNode node) { if (queue.isEmpty()) { return; } while (queue.size() > 0) { node = queue.poll(); if (node.getLeft() != null) { queue.add(node.getLeft()); } if (node.getRight() != null) { queue.add(node.getRight()); } if (node.getLeft() != null && node.getRight() != null) { list.add(node.getData()); } } }
I got error messege from my test class.
I can not use "continue package System.arraycopy() clone() assert() Arrays class Array class Collections class Collection.toArray() Reflection APIs Inner or nested classes" in this assignment.
492 493 g 494 @Test (timeout = TIMEOUT) public void testLeavesDescending() { LinkedListStep 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