Q1_20251108091125.webp
N

Q1_20251108091125.webp

Do not pay attention to real meaning of objects, variables and their values in the questions below.
Question 1: (4 marks)
In this question you should complete some methods in MyList.java file.
The class Canoe with 3 data members: driver, rate and color is given and you do not need to edit it. The
MyList class is a linked list of Canoe objects. The following methods should be completed:


void addLast(String xDriver, int xRate, int xColor) - check if xDriver.charAt(0) == 'A' then do nothing,
otherwise add new node with driver=xDriver, rate-xRate, color=xColor to the end of the list. (rate
and color can get arbitrary, even negative values).
void f1() - Do not edit this method. Your task is to complete the addLast(...) method above only.
Output in the file f1.txt must be the following:
(B,5,3) (C,6,5) (D,2,4) (E,7,9) (F,4,-7) (G,-3,2)

void f2()-There are 3 given Canoe objects x, y, z in this function. Write statements to insert x,
y and z to the list so that x, y, z will be at positions 1, 2 and before tail (The head's position is 0).
Output in the file f2.txt must be the following:
(C,9,8) (D,6,3) (E,8,5) (F,5,4) (1,4,9) (J,3,7)
(C,9,8) (X,1,2) (Y,2,3) (D,6,3) (E,8,5) (F,5,4) (1,4,9) (2,3,4) (J,3,7)
1
• void f3() - Remove the 3rd node having color> minimum color. (If such node does not exist then
do nothing). Output in the file f3.txt must be the following:
(C,7,6) (D,6,7) (E,3,8) (F,7,9) (G,8,7) (H,4,9) (1,8,3) (J,5,4)
(C,7,6) (D,6,7) (F,7,9) (G,8,7) (H,4,9) (1,8,3) (J,5,4)
Zoom
void f4()- Find the first node p having driver = J. Reverse elements before p. The content of the
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
+ 100%
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
3,507
Lượt bình luận
0
Rating
0.00 star(s) 0 đánh giá

Share this media

Back
Bên trên Bottom