Q1_20251108091135.webp
N

Q1_20251108091135.webp

Ting the remove paving unvereverse elements verore pime comme Of He
output file f4.txt must be the following:
(C,9,8) (D,11,12) (E,8,7) (F,1,2) (1,7,9) (J,6,8) (K,5,6) (L,9,8) (M,3,4)
(1,7,9) (F,1,2) (E,8,7) (D,11,12) (C,9,8) (J,6,8) (K,5,6) (L,9,8) (M,3,4)
Question 2: (4 marks)
In this question you should complete some methods in BSTree.java file.
The class Canoe with 3 data members: driver, rate and color is given and you do not need to edit it. The
BSTree class is a binary search tree of Canoe objects. The variable rate is the key of the tree, thus it must
be unique. The following methods should be completed:


void insert(String xDriver, int xRate, int xColor) - check if xDriver.charAt(0) == 'B' then do nothing,
otherwise insert new Canoe object with driver=xDriver, rate-xRate, color-xColor to the tree (rate
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:
(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 breadth-first traversal from the root but display to file f2.txt leaf nodes only.
Hint: Copy the function breadth(...) to function breadth2(...) and modify it. Output in the file f2.txt
must be the following:
(C,8,2) (D,6,1) (E,9,4) (F,2,-1) (G,7,3) (H,10,8) (1,1,7) (J,3,9) (K,-1,5) (L,5,10) (M,4,6)
(G,7,3) (H,10,8) (K,-1,5) (M,4,6)
void f3()-Suppose p is the 3rd node having 2 non-empty children when performing breadth-first
traversal of the tree. Delete p by copying. Output in the file f3.txt must contain 3 lines: statements
to display line 1 and line 3 already are given. If p has father fa then use the statement
f.writeBytes(fa.info + "\r\n"); to display fa in line 2.
(C,8,2) (D,6,1) (E,9,4) (F,2,-1) (G,7,3) (H,10,8) (1,1,7) (J,3,9) (K,-1,5) (L,5,10) (M,4,6)
(D,6,1)
(C,8,2) (D,6,1) (E,9,4) (1,1,7) (G,7,3) (H,10,8) (K,-1,5) (J,3,9) (L,5,10) (M,4,6)
Zoom
+ 100%
2
Close
Chưa có bình luận nào.

Thông tin

Category
CSD201
Thêm bởi
Ngọc Huyền
Ngày thêm
Lượt xem
2,495
Lượt bình luận
0
Rating
0.00 star(s) 0 đánh giá

Share this media

Back
Bên trên Bottom