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

Binary Search Tree : Descending order method. /** * Creates a list

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

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!