The class Camel with 3 data members: desert, step and type is given and you do not need to edit it. The
☑Kizspy. me BSTree class is a binary search tree of Camel objects. The variable step is the key of the tree, thus it must
be unique. The following methods should be completed:
.
void insert(String xDesert, int xStep, int xType) - check if xDesert.charAt(0) == 'B' then do nothing,
otherwise insert new Camel object with desert-xDesert, step-xStep, type-xType to the tree (step
and type can get arbitrary, even negative values).
void f10) - Do not edit this method. Your task is to complete the insert(...) method above only.
Output in the file f1.txt must be the following:
(A,7,9) (C,4,3) (D,8,6) (E,2,5) (Y,6,-7) (F,-6,7)
(F,-6,7) (E,2,5) (C,4,3) (Y,6,-7) (A,7,9) (D,8,6)
. void f2() - Perform pre-order traversal from the root but display to file f2.txt nodes with type>4
only. Hint: Copy the function preOrder (...) to function preOrder2(...) and modify it. Output in the
file f2.txt must be the following:
(C,8,2) (D,6,1) (F,2,-1) (1,1,7) (K,-1,5) (J,3,9) (L,5,10) (M,4,6) (G,7,3) (E,9,4) (H,10,8)
(1,1,7) (K,-1,5) (J,3,9) (L,5,10) (M,4,6) (H,10,8)
Zoom
void f30) Suppose p is the 3rd node when performing the pre-order traversal of the tree.
Calculate number of nodes in the sub-tree with root p and suppose this number is k, then set
Close
+ 100%