Question: 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.

BST java /** * Creates a list of all leaf nodes present

in the tree in * descending order. * * Should run in

@Test ( timeout = TIMEOUT.) public void testLeavesDescending) LinkedList(); assertEquals (emptyList, bst.listLeavesDescending)); ArrayList (Arrays.asList(binaryArrayl)); bst new BST(coll); Integer[] array2= {15, 13, 10, 7, 4, 1): List(Arrays.asList(array2)) assertEquals(list, bst.listLeavesDescending)); collnew ArrayList (Arrays.asList(binaryArray2)) bst new BST(coll); new BSTo cott)s Integer[l array3 - 115, 13, 10, 7, 5, 3, 1; list = new LinkedList(Arrays.asList(array3 )); assertEquals(list, bst.listLeavesDescending))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!