Lab 9
Array Based List
Array Based List Insert (read)
The purpose of this lab is to practice with the an array based list
data structure and understand the data structure's efficiency for
insertion and removal operations (shifting elements). For this lab you
will complete the definition of the given class ArrayList
and write the member fuction prototypes and definitions for
insert, remove, and search.
The behavior and pseudocode of the definitions are listed below. In
addition, complete the cases for the menu based
lab9.cpp.
- bool insert(const int pos, const T elem) - This function will
insert the passed elem to the given position (position 1 will reference
the 0th index of the array).
Validate that the given
position is within [1..count+1] and that the current count is less than
the capacity MAX; if not return false. Otherwise, this function
will shift elements and insert the given element to the correct position ,
increment count, and return true.
- bool remove(const T elem) - This function will traverse the list
for the first occurrence of the passed element. Store the index
(position) of the element and shift the elements preceding
the found value, decrement count, and return true. Return false, if
the element was never found.
- int search(const T elem) - This function will traverse the list
for the first occurrence of the passed element and return the index
at which it was found. If the element was never found return -1.
Within main, output the corresponding position, not the index
(index+1 == position)
Show me your completed code in class or have
the file within your depository directory.
~/2020_S19/wk9/lab9.cpp