CSD201_-_SP_2024_-_B3W_-_T5_1885.webp
Izumi99

CSD201_-_SP_2024_-_B3W_-_T5_1885.webp

  • Media owner Izumi99
  • Ngày thêm
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) == 'N' is not inserted to the tree. The output in file f1.txt should be as follows (line 1: Breadth first traversal, line 2: In-order traversal)
Χ,5,2) (Ρ,1,3) (M,9,5) (R,4,8) (F,7,4) (Q,8,7)(
(P,1,3) (R,4,8) (X,5,2) (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.
Output in the file f2.txt must be the following (line 1: Breadth first traversal for whole the tree,line 2: pre-order traversal for f2 requirement):
(P,7,9) (D,4,3) (G,9,6) (H,2,5) (B,6,4) (X,8,9) (L,1,8)
(D,4,3) (H,2,5) (L,1,8)
void f3() - Perform a new traversal method to visit all nodes in the BST with the constraint: visit the nodes in the descending order of weight. Output in the file f3.txt must be the following:(Τ,8,-5) (M,7,2) (P,6,3) (R,5,9) (S,4,1) (L,2,5) (Y,1,6)
2
void f4() Print out leaf nodes with color<7 of the tree. Output in the file f4.txt must be the follwing: (line 1: pre-order traversal for whole the tree, line 2: leaf nodes for f4 (by pre-order traversal))
(A,6,5) (B,2,7) (Ρ,1,9) (C,3,-8) (F,4,2) (D,5,-3) (E,8,3) (G,7,4) (Q,9,1)
(D,5,-3) (G,7,4) (Q,9,1)
void f5() - How many internal nodes are there in the BST? Output in the file f5.txt must be the
following: (line 1: in-order traversal, line 2: the amount of internal nodes)
(L,1,5) (H,2,6) (Q,3,1) (D,4,3) (B,6,-4) (Μ,7,9) (Χ,8,7) (6,9,-6)
4
Zoom
+ 100%
Close

Chưa có bình luận nào.

Thông tin

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

Image metadata

Filename
CSD201_-_SP_2024_-_B3W_-_T5_1885.webp
File size
247.5 KB
Dimensions
916px x 988px

Share this media

Back
Bên trên Bottom