COMP225 : Algorithms and Data Structures
Practical Week 8
Exercises
- Compile and run the programs pq.cpp and pq1.cpp provided in week 7 lectures
and make sure that you understand how they work.
- (*) Since priority queue and heap operations are analgous, we can write
a simple-minded heapsort by :
- Inserting all array values into a priority queue (corresponds to step 1 make a heap)
- One by one remove largest from priority queue and put into array (corresponds to step 2)
Submit simpleheapsort.cpp to web-CT
. - If you haven't used exceptions before you may wish to first read
exceptions in c++ .
- (*) Now we will be more object-oriented and generalised. We will use Carranos
files
Note that if using dev-cpp all files must be ADD'ed to the same project.
If using unix then put in same directory(folder) and use g++ *.cpp
(it is clever enough to work out which files include which and compile and link them appropriately as long as there is only one main).
Write a main program which implements heapsort according to the algorithm discussed in lectures( and/or Carrano). Complete the program template heapsort.cpp .
Submit heapsort.cpp via web-CT
. - (*) Experimentally compare your implementation with another sorting function, for example quicksort for an array. (Run your algorithm for a number of sizes of array. Do a similar test for another sorting algorithm. Plot the two graphs and add it to your portfolio; include a short explanation comparing the two graphs.)

