In this question you should complete some methods in BSTree.java file.
ne class Cat with 3 data members: place, weight and color is given and you do not need to edit it. The BSTree class is a binary search tree of Cat objects. The following methods should be completed:
void insert(String xPlace, int xWeight, int xColor) - The variable weight is the key of the BSTree,thus it must be unique.
void f1() Your task is to add statements in the insert(...) method so that any node with xPlace.charAt(0) == 'F' is not inserted to the tree. The output in file f1.txt should be as follows (line1: Breadth first traversal, line 2: In-order traversal)(Χ,5,2) (Ν,3,6) (M,9,5) (P,1,3) (R,4,8) (Q,8,7)
(P,1,3) (N,3,6) (R,4,8) (X,5,2) (Q,8,7) (M,9,5)
void f2() - Perform pre-order traversal for the right branch of the BST, but display to file f2.txt nodes with color<8 only.
Hint: Copy the function preOrder(...) to function preOrder2(...) and modify it.
Output in the file f2.txt must be the following (line 1: Breadth first traversal, line 2: pre-order traversal)
(P,7,9) (D,4,3) (G,9,6) (H,2,5) (B,6,4) (X,8,9) (L,1,8) (N,3,1)
(G,9,6)
void f3() - Perform a new traversal method to visit all nodes in the BST with the constraint: visit the nodes in the descending order of weight. Output in the file f3.txt must be the following:(T,8,-5) (M,7,2) (P,6,3) (R,5,9) (S,4,1) (1,2,5) (1,1,6)
+ 90%
Zoom
Close