Question: How can i complete this c++ function without using remove void elimZeros (): which removes the zeros from the list. The function must have complexity
How can i complete this c++ function without using "remove" void elimZeros (): which removes the zeros from the list. The function must have complexity in O (N) time in the worst case and be in-place.
This is what I have so far:
void AList::elimZeros(){ ListItemType j = 0;
for(int i = 0; i < listSize; i++){ //move 0 to the end of the list
if(listArray[i] != 0){ swap(listArray[j],listArray[i]);
j++;
listSize -- ;
}
}
}
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
