Answered step by step
Verified Expert Solution
Link Copied!

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.

image text in transcribed

image text in transcribed

@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

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

Beginning ASP.NET 2.0 And Databases

Authors: John Kauffman, Bradley Millington

1st Edition

0471781347, 978-0471781349

More Books

Students also viewed these Databases questions

Question

What is database?

Answered: 1 week ago

Question

What are Mergers ?

Answered: 1 week ago