Answered step by step
Verified Expert Solution
Link Copied!

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 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; } } /**  * 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.

image text in transcribed

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() { LinkedList emptyList = new LinkedList() ; assertEquals(emptyList, bst. listLeavesDescending); 495 496 497 ArrayList(Arrays.asList(binaryArray1)); bst = new BST(coll) ; 498 499 500 Integer] array2 = {15, 13, 10 , 7, 4, 1}; List(Arrays.asList (array2)); assertEquals(list, bst. listLeavesDescending(); 501 502 503 504 coll = new ArrayList(Arrays.asList(binaryArray2)); bst = new BST(coll) ; 505 506 507 508 Integerlarray3 = {15, 13, 10, 7, 5, 3, 1 }; list = new LinkedList(Arrays.asList(array3)); assertEquals(list, bst. listLeavesDescending()); 509 1 a BSTStudentTests > testLeavesDescending) 1 + E E, NC D 26 tests stion1 2ms java.lang. AssertionError : 3ms Expected :[15, 13, 10, 7, 4, 1] 2ms Actual : [8, 6, 12, 2, 14] 2ms emptyList = new LinkedList() ; assertEquals(emptyList, bst. listLeavesDescending); 495 496 497 ArrayList(Arrays.asList(binaryArray1)); bst = new BST(coll) ; 498 499 500 Integer] array2 = {15, 13, 10 , 7, 4, 1}; List(Arrays.asList (array2)); assertEquals(list, bst. listLeavesDescending(); 501 502 503 504 coll = new ArrayList(Arrays.asList(binaryArray2)); bst = new BST(coll) ; 505 506 507 508 Integerlarray3 = {15, 13, 10, 7, 5, 3, 1 }; list = new LinkedList(Arrays.asList(array3)); assertEquals(list, bst. listLeavesDescending()); 509 1 a BSTStudentTests > testLeavesDescending) 1 + E E, NC D 26 tests stion1 2ms java.lang. AssertionError : 3ms Expected :[15, 13, 10, 7, 4, 1] 2ms Actual : [8, 6, 12, 2, 14] 2ms

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

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions

Question

What do semistrong market efficiency tests attempt to test for?

Answered: 1 week ago

Question

Different formulas for mathematical core areas.

Answered: 1 week ago