Question: Need help with fixing up my code so it can past the tests not sure what is wrong with it . C + + void
Need help with fixing up my code so it can past the tests not sure what is wrong with it
C void prependT value
if count capacity
inflate;
for int i count; i; i
datai datai;
data value;
count;
T removeFirst
if count
throw std::outofrangeList is empty";
T removedValue data;
for int i; i T removeLast
if count
throw std::outofrangeList is empty";
T removedValue datacount;
count;
ifcount capacity
deflate;
return removedValue;
return T;
void deflate
if capacity return;
int newCapacity capacity ;
T temp new TnewCapacity;
for int i; i count; i
tempi datai;
delete data;
data temp;
capacity newCapacity;
TestArrayList::TestPrependFour failed:
Expected: equal to
Actual:
TestArrayList::TestPrependOne failed:
Expected: equal to
Actual:
TestArrayList::TestPrependTwo failed:
Expected: equal to
Actual:
Test run complete. tests run:
mathrm succeededassignments lab exercise C test.cpp
SpecTestAppendOne
ArrayListArrayListSpecTestAppendOne
ArrayList
Introduction
user of the class can insert new data into the list at the end. The list will automatically inflate itself, which doubles its capacity, if needed.
Tasks
Implement the following methods in ArrayList.h:
void value;
The data element given by value should be inserted at the beginning of the list, as opposed to the end which is the way append works
T removeFirst
This method should remove the first data element from the list, and should return it
T removeLast
This method should remove the last data element from the list, and should return it
Note
For the removeFirst and removeLast functions above, if the removal procedure results in a situation where we are using "too much space", the storage capacity should be decreased deflated
Assume that "too much space" is defined as the capacity is strictly greater than twice the number of elements in the list. That is to say, if we were to cut the capacity in half, we would still have space available to insert
an element.
Therefore, our policy will be anytime we detect that we are using less than half the capacity, we should call our deflate function, which halves the capacity while preserving the data.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
