Answered step by step
Verified Expert Solution
Question
1 Approved Answer
BST java /** * Creates a list of all leaf nodes present in the tree in * descending order. * * Should run in O(n).
BST java /** * 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 List listLeavesDescending() { 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; } } private void listLeavesDescendingHelper(List list, Queue> queue, BSTNode node) { if (queue.isEmpty()) { return; } while (queue.size() > 0) { BSTNode tmp = queue.poll(); if (tmp.getLeft() != null && tmp.getRight() != null) { list.add(node.getData()); } if (tmp.getLeft() != null) { queue.add(tmp.getLeft()); } if (tmp.getRight() != null) { queue.add(tmp.getRight()); } } }
This is my code.
I got error messege from the test.
@Test ( timeout = TIMEOUT.) public void testLeavesDescending) LinkedList
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