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 prepend(T value){
if (count == capacity){
inflate();
}
for (int i = count; i>0; i--){
data[i]= data[i-1];
}
data[0]= value;
count++;
}
T removeFirst(){
if (count ==0){
throw std::out_of_range("List is empty");
}
T removedValue = data[0];
for (int i=0; i T removeLast(){
if (count ==0){
throw std::out_of_range("List is empty");
}
T removedValue = data[count-1];
count--;
if(count capacity /2){
deflate();
}
return removedValue;
return T();
}
void deflate(){
if (capacity =1) return;
int newCapacity = capacity /2;
T* temp = new T[newCapacity];
for (int i=0; i count; i++){
temp[i]= data[i];
}
delete[] data;
data = temp;
capacity = newCapacity;
} TestArrayList::TestPrependFour failed:
Expected: equal to 8
Actual: 4
TestArrayList::TestPrependOne failed:
Expected: equal to 2
Actual: 1
TestArrayList::TestPrependTwo failed:
Expected: equal to 4
Actual: 2
Test run complete. 15 tests run:
12}\mathrm{ succeededassignments > lab-2> exercise-1_4> C+ test.cpp >...
}
}
Spec(TestAppendOne){
ArrayListArrayListSpec(TestAppendOne){
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.
Need help with fixing up my code so it can past

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!