Lab 4 - Queues
For this lab, implement enqueue
and dequeue
in
linkedqueue.cpp. To test your implementation,
write a main program that will has an integer queue. Read in integers from
lab4data.txt and enqueue them into the queue.
Then dequeue each interger and print its value to the screen (call front
before dequeue to get the value). Email me your modified linkedqueue.cpp
and main program.
Extra Credit (5 points)
To see how queues are faster at tail insertion than lists, try writing a
second program that uses linkedlist.cpp instead
of linkedqueue.cpp. This program will also read data from
lab4data.txt. Use the following pseudocode:
store 1st integer as the head
set previous to the 1st integer
while there is still more data to add
search for the node that contains the previous integer
insert the current integer after that node
set previous to the current integer
This will do a tail insertion into the linked list. See how long it takes
this program to run by using the time
utility (see
man time
for more information). Compare the runtime for
linked list and linked queue. To eliminate any variables, hard-code the
filename into both main programs (so there's no extra time spent by the
program waiting for you to type the filename). Email me your linked list
main program and how much time linked list took compared to linked queue.