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 chars. 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. Just use the standard string comparison operators and you'll get
the correct ordering.
- Implement the linked list declared in
List.h. - Store values in ascending asciibetical order (
AbeforeZbeforea). - You can't use any container classes 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 destructor cleans up the list.
count()Get the number of values in the list.insert(value)Insertvalueat its correct position in the list.lookup(index)Get the value stored atindex. Ifindexis invalid, throw astd::out_of_rangeexception.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. Ifreverseis false (the default), print the list in it's natural (ascending) order:If[Atropos, Clotho, Lachesis]reverseis true, print it in descending order:[Lachesis, Clotho, Atropos]remove(index)Remove the value stored atindexand return it. Ifindexis invalid, throw astd::out_of_rangeexception.remove(value)Remove all copies ofvaluefrom the list. Return the number of values that you removed.
- Recursion works very nicely on linked lists.
- 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.cppfile).