Lab ListStaticArray - List ADT implemented with dynamic array
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 static array and a client. Since VPL does not (yet) allow for C++ multifile projects, all the code is in the listAll.cpp
source code file.
Your task is to complete the implementation of the following member functions for the List
class:
-
void elimOdds(): removes the odd integers from the list. For example if L contains
(5, 23, 10, 17, 8)
, after callingL.elimOdds()
the content of L will be(10, 8)
. Your algorithm should be worst case O(n) where n is the length of the list. Honor points if you can design an in-place algorithm. -
void reverse(): reverses the list in place For example if
L
contains(1, 2, 3, 4)
, callingL.reverse()
will change the list to(4, 3, 2, 1)
. Your algorithm should be in-place. It should be O(n) in the worst case. -
int mode() const: returns the mode of the list, i.e. the most repeated element. You may assume that the list contains only positive numbers in the range of 1 to 100. If there is no mode, the member function will return -1. Your algorithm should be O(n) in the worst case.
Examples:
- If the list
L
contains(1, 2, 1, 1)
,L.mode()
will return1
. - If the list
L
contains(1, 2, 2, 1)
,L.mode()
will return-1
because the list has no mode, i.e. there are two or more numbers that repeat the same number of times. - If the list
L
contains(33,22,44)
,L.mode()
will return-1
because the list has no mode, i.e. there are two or more numbers that repeat the same number of times.
- If the list
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.eo
: eliminate the odds (by calling theelimOdds
function).r
: reverse the list.m
: print the mode of the list.q
: quit the client program.
A Makefile
is provided so that you may compile the program by simply typing make
in the linux command line.
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