(N,6,8) (A,9,3) (W,5,3) (1,4,6) (5,7,5) (D,3,9)
(D,3,9) (1,4,6) (W,5,3) (5,7,5) (A,9,3)
Question 2: (5 marks)
In this question you should complete some methods in BSTree.java file.
The class Bird 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 Bird 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) == 'X' is not inserted to the tree. The expected output in file f1.txt should be as follows: (line 1: Breadth first traversal, line 2: In-order traversal)
M,9,5) (F,7,4) (N,3,6) (Q,8,7) (P,1,3) (R,4,8)(
(P,1,3) (N,3,6) (R,4,8) (F,7,4) (Q,8,7) (M,9,5)
void f2()-Perform pre-order traversal for the left branch of the BST, but display to file f2.txt nodes with color>4 only.
Hint: Copy the function preOrder(...) to function preOrder2(...) and modify it.
The expected output in the file f2.txt should 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) (L,1,8) (N,3,1)
(H,2,5) (L,1,8)
2
Zoom
+ 91%
Close