Lab 2: A Queue With Intelligence

http://www.cs.tufts.edu/comp/15/labs/lab2

Overview

Last week you learned about queues and implemented a simple one. However, not all queues in the the real world operate under a first-come first-served rule. For instance, if Tufts is adding maintenance requests to a queue, a new request (say, a broken window at the Campus Center) might have a higher priority than some of the previous entries. Enter the priority queue. This week, you'll still be removing some items from the front of the queue. However, we'll keep them sorted by their priority by inserting them within the queue based on where they belong, not just tacking them all at the end. We'll also remove items from within the queue to simulate a maintenance request that gets removed.

Getting started

Start by copying the files from /comp/15/labs/lab2/ into your home directory (I recommend making a subdirectory called comp15 with another directory inside it called lab2). The files are:

You can copy them all in one command:

cp /comp/15/labs/lab2/* .

Compiling and Running

Edit, Save, and Compile Often!!!

You can use one of two compilers: g++ or clang++. I recommend using clang++ because it gives much better error messages.

clang++ main.cpp priorityQueue.cpp Node.o WorkOrder.o -o mytest
or
g++ -Wall -Wextra main.cpp priorityQueue.cpp Node.o WorkOrder.o -o mytest

To debug your code (especially if you have segmentation faults) you can use gdb (see my quick reference on using the debugger). I also urge you to try running your program using valgrind, a very cool program that checks your program for pointer and allocation problems. Run it like this:

valgrind ./mytest

Providing your Code

As always, you should provide your source code before you leave. The assignment name is lab2.

provide comp15 lab2 priorityQueue.cpp main.cpp