BST Exercise
Use eclipse for this exercise.
- Copy all files from Shared Files, BST Exercise folder.
- Create a class Disk. Disk contains four fields: model (String),
size (int), measure (String, for GB or TB), and performance index (int).
- Disk needs a constructor to initialize all fields and a toString
method. Make the class Comparable and write a compareTo method
that compares Disks
based on the size of the disk. Make sure your comparison accounts
for the fact that some numbers are in GB and some are in TB. Also
write a method to create a Comparator which compares Disks
based on the performance rating.
- Your client code should do the following:
- In main create a BST of Disks which will order the Disks
by size. Pass this BST to your build function. Then
create an iterator to visit the disks in preorder, and use
this iterator to print all the disks.
Create another iterator to visit the disks in inorder
and use this iterator to print all the disks.
- The build function will open the disks.dat file,
read in each disk and add it to the BST.
- Run your program, and check that the second iterator
prints the Disks in size order.
- Add a function that prompts for a size and prints all disks
of that size. Add a call to this function at the end of main.
- Change main so that the BST is ordered by performance rating.
Remove the call to the function that prints based on size.
Run the program again and check that the second iterator
prints the Disks in rating order.
Email Me |
Office Hours |
My Home Page |
Department Home |
MCC Home Page
© Copyright Emmi Schatz 2017