0% found this document useful (0 votes)
65 views2 pages

CSD201 01

Students are instructed to complete programming exercises involving linked lists and binary search trees of Car objects. They are not allowed to use outside resources during the exam. The exercises involve adding, deleting, and sorting nodes in the data structures based on attributes of the Car objects like owner name and price. Output must be written to multiple text files and conform to the given formats.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views2 pages

CSD201 01

Students are instructed to complete programming exercises involving linked lists and binary search trees of Car objects. They are not allowed to use outside resources during the exam. The exercises involve adding, deleting, and sorting nodes in the data structures based on attributes of the Car objects like owner name and price. Output must be written to multiple text files and conform to the given formats.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

INSTRUCTIONS

 Students are allowed to use any books and materials.


 Students are NOT allowed to use mobile phone, Internet, Intranet, Yahoo Messenger, CMS,
USB, and all applications that help share information.
 Students are NOT allowed to transmit information and exchange materials with any other
during the examination period.
Follow the steps below to complete PE:
1. Down load given files to your computer.
2. Steps to do question 1 (do the same for questions 2 and 3):
Open NetBeans, create a new project named Q1 (or Q1X, Q1Y, ...). Check the item “Create
Main Class”, and type Main in the text box behind it as below:

Copy all files in the folder Q1_given into the src folder, then copy the file data.txt to the project
folder (outside of src).
3. Submittion: Create a folder named CSD201_PE. Copy only projects containing functions you
have done into this folder. When submitting, you select the folder CSD201_PE (do not need to
compress it).
4. The version of Java being used must be 1.7 or 1.8
------------------------------------------------------------------------------------------------------------------------
Question 1: (4 marks)
In this question you should complete some methods in MyList.java file.
The class Car with 2 data members: owner and price is given and you do not need to edit it. The
MyList class is a linked list of Car objects. The following methods should be completed:

 void addLast(String xOwner, int xPrice) - check if character at last of xOwner = 'A' or
xPrice>50 or xPrice<0 then do nothing, otherwise add new car with owner=xOwner,
price=xPrice, price=xPrice to the end of the list. (price can get arbitrary value, even
negative).

 void f1() – This method is used to test the addLast methode above. You do not need to edit
this function. Output in the file f1.txt must be the following:
(B,3) (C,7) (D,2) (E,6) (F,4)

 void f2() – There is a given objects x. You should write statements so that x will be add
(X,1) after the first element which has price is prime numer. Output in the file f2.txt must be
the following:
(C,9) (D,6) (E,8) (F,2) (I,6)
(C,9) (D,6) (E,8) (F,2) (X,1) (I,6)

 void f3() – Delete the first node in list having price is square number. Output in the file
f3.txt must be the following:
(C,9) (D,5) (E,3) (F,5) (I,6)
(D,5) (E,3) (F,5) (I,6)

 void f4() – Sort only the element in list having price is prime number ascendingly. Output in
the file f4.txt must be the following:
(C,9) (D,6) (E,5) (F,13) (I,2) (J,1)
(C,9) (D,6) (I,2) (E,5) (F,13) (J,1)

Question 2: (4 marks)
In this question you should complete some methods in BSTree.java files.
The class Car with 2 data members: owner and price is given and you do not need to edit it. The
BSTree class is a binary search tree of Car objects. The variable price is the key of the tree. The
following methods should be completed:

 void insert(string xOwner, int xPrice) - check if the last character of xOwner is 'X' or
xPrice>50 or xPrice <0 then do nothing, otherwise insert new car with owner=xOwner,
price=xPrice to the tree.

 void f1() – You do not need to edit this function. Your task is to complete the insert(...)
function above only. Output in the file f1.txt must be the following:
(A,5) (C,2) (E,4) (G,3) (B,10) (D,6) (F,7)
(C,2) (G,3) (E,4) (A,5) (D,6) (F,7) (B,10)

 void f2() – Perform post-order traversal from the root but display to file f2.txt nodes having
price is prime number. Hint: Copy the function preOrder(...) to preOrder2(...) and modify
it. Output in the file f2.txt must be the following:
(C,6) (D,2) (F,4) (H,3) (I,5) (E,8) (G,7)
(H,3) (I,5) (D,2) (G,7)

 void f3() – Perform pre-order traversal from the root and delete by copying the first node
having both 2 sons and price is prime numer. Output in the file f3.txt must be the following:
(C,8) (D,6) (E,9) (F,2) (G,7) (H,1) (I,3) (J,5) (K,4)
(C,8) (D,6) (E,9) (H,1) (G,7) (I,3) (J,5) (K,4)

 void f4() – Perform post-order traversal from the root and find the first node p having right
son and price is prime number. Rotate p to left about its’ right son. Output in the file f4.txt
must be the following:
(C,8) (D,6) (E,9) (F,2) (G,7) (H,1) (I,3) (J,5) (K,4)
(C,8) (D,6) (E,9) (I,3) (G,7) (F,2) (J,5) (H,1) (K,4)

You might also like