CS253: Software Development with C++

Fall 2022

Linked List

Linked List Lab                

This lab concerns linked lists and dynamic memory allocation. A video introduction is available.                 

These are tasks, not questions to be answered. All that you turn in is the resultant code & Makefile.                 

  1. Copy the directory ~cs253/Lab/LinkedList to a convenient place in your home directory.
  2. Compile & link main.cc & ll.cc together into an executable named link.
  3. Create a Makefile so that you won’t have to type g++ again. Use at least -Wall.
    • Its default target must be link. That is, if you just type make, it will create an executable program called link.
    • It is not acceptable to use a Makefile produced by cmake. That Makefile is tied to the directory you wrote it in, and so won’t work for anybody else. Instead, you must write your own Makefile.
    • When make is run, warnings or errors are not acceptable.
  4. Run the resultant executable ./link; observe how the program works. Reading the code may help.
  5. Fix the memory leak in .remove().
  6. Find uses of this->, which are always suspicious. Remove them. Does everything still work?
  7. .initialize() methods often indicate that the author doesn’t understand constructors. Turn them into ctors.
  8. Are your ctors using member initialization lists? Make them do so.
  9. The method .remove() uses a pointer argument to return a value. C++ programmers prefer reference arguments to pointers. Change the method to use a reference argument, instead.
  10. Add a method .print() that displays the list, with one space between each data item, and a newline after the last one. There should not be a space after the last datum. Add another case (4. print) in main() that uses it.
  11. Using .print() is tacky. Replace it with an overloaded << operator so you can use << on a LinkedList object, just like any other type.
  12. Are there any remaining memory leaks? What happens when a LinkedList object is destroyed? Fix that.
  13. Create a tar file results.tar containing your work:
    tar -cvf results.tar Makefile main.cc ll.cc ll.h
  14. Create an empty directory and test your results.tar in it.

How to submit your work:                

In Canvas, check in the file results.tar to the assignment “Lab05”. It’s due 11:59ᴘᴍ MT Saturday, with a 24-hour late period for a 25% penalty.                 

How to receive negative points:                

Turn in someone else’s work.