Lab ListLinkedList - List ADT implemented with linked list
The partial source code for this lab is at http://vpl.ccom.uprp.edu.
You are given an implementation of the integer list ADT using linked list and a client. Since VPL does not (yet) allow for C++ multifile projects, all the code is in the linkedListAll.cpp
source code file.
Your task is to complete the implementation of the following member functions:
-
bool isSorted(): determines if the list is sorted in ascending order. For example, if the list
L
currrently contains(4, 9, 20)
thenL.isSorted()
returnstrue
. Your algorithm should be worst case O(n) where n is the length of the list. -
void insertInOrder(ElementType val): given an integer val and assuming the list is already sorted in ascending order, this function will insert val into the list, conserving its ascending order. For example, if
L
contains(4, 9, 20)
then afterL.insertInOrder(15)
the listL
contains `(4, 9, 15, 20). This algorithm should also be worst case O(n) where n is the length of the list. -
LList merge(const LList & b) const: given a second list (that is in ascending order), this function returns a third (ordered) list with the elements of the invoking list and the argument list. For example, if
L
contains(4, 9, 20)
andM
contains(10, 23)
thenL.merge(M)
returns a list that contains(4, 9, 10, 20, 23)
. This algorithm should also be worst case O(n) where the length of each list is n.
The provided client takes care of asking the user for a command and then invoking the corresponding function. The client understands the following commands:
i {value} {position}
: insert a value at a position. For example, ifL
contains(4,8,1)
, after the commandi 10 2
it will contain(4,8,10,1)
.e {position}
: erase the element at position. For example, ifL
contains(4,8,1)
, after the commande 0
it will contain(8,1)
d
: display the contents of the list.is
: calls theisOrdered()
function then prints message.io {value}
: insert value into the list to maintain its order. For example, ifL
contains(3, 6, 9)
, after the commandio 4
it will contain(3, 4, 6, 9)
.m
: merge the list(2,4,10)
with the current list and print the result.q
: quit the client program.
Please include the name of the programmers at the beginning of the file. Also provide comments before each of the functions. You should follow good programming practices such as:
- good variable names
- appropriate indentation
- modularity
- readability