void insert(String xMaker, int xVolume, int xColor) - check if xMaker.charAt(0) == 'A' then do nothing, otherwise insert new Bottle object with maker=xMaker, volume=xVolume, color=xColor to the tree (volume and color can get arbitrary, even negative values).
void f1() - 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:
(B,9,4) (C,4,3) (D,8,6) (Y,6,-7) (E,2,5) (F,-6,7)
(Y,6,-7) (C,4,3) (B,9,4) (E,2,5) (D,8,6) (F,-6,7)
void f2() - Perform pre-order traversal from the root but display to file f2.txt nodes with volume<7 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) (E,9,4) (G,7,3) (H,10,8) (1,1,7) (K,-1,5) (M,4,6) (J,3,9) (L,5,10)
(D,6,1) (F,2,-1) (1,1,7) (Κ,-1,5) (Μ,4,6) (J,3,9) (L,5,10)
void f3() - Suppose p is the 6th node in post-order traversal from the root. Delete the node p by copying. Output in the file f3.txt must be the following:
(F,2,-1) (D,6,1) (G,7,3) (Μ,4,6) (K,-1,5) (1,1,7) (L,5,10) (J,3,9) (H,10,8) (E,9,4) (C,8,2)
(F,2,-1) (D,6,1) (G,7,3) (Μ,4,6) (K,-1,5) (L,5,10) (J,3,9) (H,10,8) (E,9,4) (C,8,2)
void f4() - Suppose p is the 3rd node having right child in pre-order traversal from the root. Calculate the number of nodes in the sub-tree with root p. If this number is k then change p.info.volume to 100+k. Output in the file f4.txt must be the following:(C,8,2) (D,6,1) (F,2,-1) (E,9,4) (G,7,3) (H,10,8) (1,1,7) (K,-1,5) (M,4,6) (J,3,9) (L,5,10)
2
(C,8,2) (D,6,1) (F,2,-1) (E,9,4) (G,7,3) (H,106,8) (1,1,7) (Κ,-1,5) (Μ,4,6) (J,3,9) (L,5,10)
Question 3: (2 marks)
In this question you should complete some methods in Granh java file
+ 100%
Zoom
Close