Linked Lists
This lab concerns the linked lists and dynamic memory allocation.
                
- Copy the directory
~cs253/Lab/LinkedList
to a convenient place in your home directory.
- Compile & link
main.cc
& ll.cc
together.
- Create a
Makefile
so that you won't have to type g++
again.
Use at least -Wall
.
- Run the resultant executable; observe how the program works.
Reading the code may help.
- Are there any memory leaks? If so, fix them.
- Find uses of
this->
, which are always suspicious. Remove them.
Does everything still work?
.initialize()
methods often indicate that the author
doesn't understand constructors. Turn them into ctors.
- Are your ctors using member initialization lists? Make them do so.
- The method
.remove()
uses a pointer argument to return a value.
How crass—use a reference, instead.
- Add a method
.print()
that displays the list.
Add another case in main()
that uses it.
- Using
.print()
is tacky. Replace it with an overloaded <<
operator so you can use <<
on a LinkedList
object,
just like any other type.
- Are you sure that you have no memory leaks? What happens when
a
LinkedList
object is destroyed? Fix that.
- Show your work to the TA for personal validation and approval of
your life choices.