CS253: Software Development with C++

Spring 2018

Linked List

Linked Lists

This lab concerns the linked lists and dynamic memory allocation.

  1. Copy the directory ~cs253/Labs/LinkedList to a convenient place in your home directory.
  2. Compile & link main.cc & ll.cc together.
  3. Create a Makefile so that you won't have to type g++ again.
  4. Run the resultant executable; observe how the program works. Reading the code may help.
  5. Are there any memory leaks? If so, fix them.
  6. Find uses of this->, which are always suspicious. Remove them. Does everything still work?
  7. Methods named .initialize() often indicate that the author of the code 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. How crass—use a reference, instead.
  10. Add a method .print() that displays the list. Add another case in main() that uses it.

For extra fame & glory:

  1. Are you sure that you have no memory leaks? What happens when a LinkedList object is destroyed? Fix that.
  2. Using .print() is tacky. Overload the << operator so you can use << on a LinkedList object, just like any other type.

Modified: 2017-03-07T12:19

User: Guest

Edit History Source
Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2015 Colorado State University
CS Building