Please read the remarks about programming problems for this course.
Read Chapters 18 and 19 in Fundamentals of C++ Programming (and any previous chapters as needed) to refresh your memory of programming C++ linked structures. Section 19.2 provides an implementation of a generic singly linked list. As an exercise to reacquaint yourself with C++, this assignment has you enhance this generic class with additional functionality.
The files
linkedlist.h
,
intlistmain.cpp
,
and
stringlistmain.cpp
comprise the original code for the generic list.
linkedlist.h
to enhance the
LinkedList
class to add the following methods:
operator[]
—the indexing operator allows
a client to access an element by its offset from the beginning
of the list. As with std::vector
s and arrays,
the method's behavior is undefined if the client provides an
index out of range (this means you need not defend against such
attempts). Your method necessarily will be less
efficient than std::vector::operator[]
because
linked lists do not support random access.
prepend
—appends an element onto the
front of the list.
(The class currently offers an insert
method that
adds an element to the back of the list.)
member
—accepts an argument of the same type as
the elements in the list. The function returns true
if the argument appears in the list; otherwise, the function
returns false
.
operator==
—returns true
if a
list passed as a parameter contains the same elements in the
same order as this list; otherwise, the method returns
false
.
This method should not
copy the elements in the list passed to it, and it
should not disturb the contents of either list.
unique
—returns true
if all of
the elements of the list are unique; that is, the list contains
no duplicate elements. If at least one of the elements in the list
appears more than one time, the method should return
false
. This method should not disturb the
contents of the list.
You should subject your class to extensive testing to verify its
correctness. You may use the file
simpletest.cpp
as a starting point for your
testing.
Submit your completed enhanced linkedlist.h
C++ source file to
http://eclass.e.southern.edu.
Be sure your name appears within a comment as the first line in each
source file you submit.