void insert(String xPlace, int xDepth, int xType) - check if xPlace.charAt(0) == 'B' then do nothing,otherwise insert new Beaver with place=xPlace, depth=xDepth, type=xType to the tree (depth and type 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:
(A,7,9) (C,4,3) (D,8,6) (E,2,5) (F,6,7)
(E,2,5) (C,4,3) (F,6,7) (A,7,9) (D,8,6)
void f2()-Perform post-order traversal from the root but display to file f2.txt nodes with type<7 only. Hint: Copy the function postOrder(...) to function postOrder2(...) and modify it. Output in the file f2.txt must be the following:
(Ε,2,8) (1,5,4) (H,6,3) (F,4,5) (G,8,7) (D,7,2) (C,3,6)
(1,5,4) (H,6,3) (F,4,5) (D,7,2) (C,3,6)
void f3() - Perform breadth-first traversal and find the second node p having left son. Delete the node having largest depth in the subtree with root p (thus if p is the leaf-node then p is deleted).Output in the file f3.txt must be the following:
(C,5,2) (D,2,1) (E,6,5) (F,1,3) (G,4,6) (H,3,4)
(C,5,2) (D,2,1) (E,6,5) (F,1,3) (H,3,4)
void f4() - Perform breadth-first traversal and find the second node p having left son, then rotate p to right. Output in the file f4.txt must be the following:
(C,5,2) (D,2,1) (E,6,5) (F,1,3) (G,4,6) (H,3,4)
(C,5,2) (F,1,3) (E,6,5) (D,2,1) (G,4,6) (H,3,4)
Zoom
+ 90%
Close