In this lab, you'll implement a sorted sequence using a singly-linked list. The sequence will store strings in "asciibetical" order.
An "asciibetical" sort is a very simple sort. It sorts strings according to the
ASCII values of their individual char
s. It doesn't always do what you
would expect -- it puts capital letters before lower case letters, and doesn't
really work for languages that use multi-byte characters -- but it's good enough
for this lab.
- Implement the linked list declared in
List.h
. - Store values in ascending asciibetical order (
A
beforeZ
beforea
). - You can't use any container types from the standard library.
- Make sure your final code doesn't print anything.
- Make sure you don't have any memory leaks.
Implement the following List
member functions in List.cpp
. You can add any
helper functions you need, but they can't be member functions of the List
and
Node
classes (since they aren't declared in List.h
).
- The default constructor creates an empty list.
- The copy constructor makes a copy of an existing list.
- The move constructor takes the values from a list that's about to be deleted.
- The destructor cleans up the list.
count()
Get the number of values in the list.insert(value)
Insertvalue
at its correct position the list.lookup(index)
Get the value stored atindex
. Ifindex
is invalid, throw astd::out_of_range
exception.print(reverse)
Print the values stored in the list. Separate values with a comma and a space. Enclose your output in square brackets and print a newline after the closing bracket. Ifreverse
is false (the default), print the list in it's natural (ascending) order:If[Atropos, Clotho, Lachesis]
reverse
is true, print it in descending order:[Lachesis, Clotho, Atropos]
remove(index)
Remove the value stored atindex
and return it. Ifindex
is invalid, throw astd::out_of_range
exception.remove(value)
Remove all copies ofvalue
from the list. Return the number of values that you removed.
- Recursion works very nicely on linked lists.
- The standard comparison operators will give you the correct ordering.
- Work on the
insert()
andprint()
(forward) functions first. These are used in almost all the tests, so you won't pass much until they work. - Don't write a
main()
function inList.cpp
. If you want to test your code, use themain()
function intest.cpp
(or some other new.cpp
file).