Mea culpa1
We have excellent beta testers in this course. When they find a bug or an error, it's like they solved a really hard puzzle. Simply put, they found that the Unit tests for lab5 were inadequate. In one case, a student had errors in all four of the methods to be implemented, and yet no unit test failed.
LEARN FROM THIS. The mere fact that some tests exist and say that your code is okay does not, in itself, mean anything at all. Maybe the tests are out-dated. Maybe they “pass” by default. Maybe some possible scenarios have not been considered.
I've tried to make this as painless as possible for you but there is some work for you to do if you want to actually understand these Priority Queues before you find yourself face to face with them on another Exam.
But FIRST: Back up your existing work, so you know you can get back to where you are now. This is almost always a very good idea, and very rarely a waste of time. (Note that there is an automated way to do everything outlined below EXCEPT completing the visit_tree method and fixing any bugs the new tests turn up. But it's not that much work to do manually and you should at LEAST know what's going to happen before you run some shell script.)
Assuming you are logged on to your ugrad account on our servers (whether you're local or remote), and your work is in ~/cs221/lab5 (i.e. there is a folder in your home directory called “cs221” and a sub-folder in that called “lab5”, and your work on this lab is in that folder), enter
The command that begins with cat takes 2 files (in this case) and concatenates the second to the end of the first.
The > Minheap.cc portion of the command directs the output to a file called Minheap.cc
in the current working directory.
If one exists already (there doessn't, it's a new folder), it would be overwritten.
The first input file is ../lab5/Minheap.cc (yes, there's a space in front of it and following it).
The filepath is relative to the current working directory (which is ~/cs221/lab5B ).
The dot-dot means go back to the parent, so ../lab5/Minheap.cc is ~/cs221/lab5/Minheap.cc
The second input file has no filepath qualifier, so it is in the current working directory.
If you've done all that, then at this point, all you have to do is edit the new Minheap.cc and complete the following method:
So all you have to do is copy whatever is in your print_tree(int, int) method and paste it into this method. Then change the two calls (so they're actually recursive, instead of calling print_tree(int, int) again), and “visit” the element instead printing its value. Once you've done that:
And now, either breathe a sigh of relief, or start fixing your bugs.
As mentioned, everything except the visit_tree(int,int,Visitor) changes can be done with a script. Yes, it even creates a zipfile of your existing lab5, but do yourself a favour and create your own too.
After that, download
lab5B.sh and move it to your home directory, then enter the following:
Caveat emptor2
This all worked for me, but if you run into trouble YOU'VE GOT A BACKUP. If you need to unzip that folder, you'll have to give yourself write and execute privileges again. Look back at the commands that are on the first page. The chmod (change-mode) command is what you want. Use 700 instead of 400. And if you do actually need to go back, personally I'd be paranoid enough at that point to copy the zip somewhere else (a backup of a backup) before proceeding.
What, it's not enough that we're throwing a new alphabet at you, there's pithy Latin too?
And finally, links to everything else:
This will download a zip file with all the source (everything except the shell script). lab5B.zip
Fri 27 Feb, 2015