I am working on an exercise in C++ and I am trying to understand how to remove an element from a list and shift the rest to the left. I wonder if there is a neat solution. Here is my version, it seems to do the job, but I have a feeling there is a better way:
Account AccountList::remove(int i){
if(i>=0 && i<size()) {
for (int n = i; n < size(); n++) {
if(i+1!=size()) {
aList[n]=aList[n+1];
}
}
sz--;
return aList[i];
} else {
return Account();
}
}
You have two issues in this.
The corrected one is given below.