Professional Documents
Culture Documents
Questions 1:: Source Price Type
Questions 1:: Source Price Type
0) void addLast(String xSource, int xPrice, int xType). Add new node with source=xSource,
price=xPrice, type=xType to the end of the list. (price and type can get arbitrary, even
negative values).
1) void f1() – Do not edit this method. Your task is to fix the addLast() method, check if
xSource.charAt(0) == 'D' then do nothing, otherwise add new node with source=xSource,
price=xPrice, type=xType to the end of the list. Output in the file f1.txt must be the
following:
(A,8,7) (B,4,2) (C,5,4) (E,6,8) (F,3,6)
2) void f2() –There are 2 given Watermelon objects g, h in this function. Suppose the list
contains at least 5 elements. Write statements to insert g and h to the list so that h will be
the 2nd, g will be the 3rd node. Output in the file f2.txt must be the following:
(A,6,5) (B,4,7) (C,9,4) (E,8,1) (F,2,3)
(A,6,5) (H,5,6) (G,2,3) (B,4,7) (C,9,4) (E,8,1) (F,2,3)
3) void f3() – Suppose the list contains at least 7 elements. Delete the third and the fourth
elements of the original list. Output in the file f3.txt must be the following:
(A,7,3) (B,8,1) (C,5,6) (E,8,3) (F,4,7) (G,3,4) (H,2,8)
(A,7,3) (B,8,1) (F,4,7) (G,3,4) (H,2,8)
4) void f4() – Sort the first 4 elements ascendingly by type. The content of the output file
f4.txt must be the following:
(A,5,8) (E,8,2) (B,6,4) (C,3,5) (G,6,2) (H,7,9) (K,1,5)
(E,8,2) (B,6,4) (C,3,5) (A,5,8) (G,6,2) (H,7,9) (K,1,5)
5) void f5() – Delete the last node of the list. The content of the output file f5.txt must be the
following:
6) void f6() – Delete the first node of the list. The content of the output file f6.txt must be the
following: