Closed robbie-vanderzee closed 5 years ago
To add, the most general fix would be to have the iterator be a component of the list object, instead of floating out of scope. Actually, this problem exists in general for anytime the list is emptied or copied. The iterator should probably be associated with the list, instead of floating out of scope.
There are lots of issues in ListTest.cpp -- this fixes some of them, and I'll follow up with the rest of the fixes. Thanks!
The makeEmpty() call in the main method leaves the iterator pointer, current, hanging. If the list before had the iterator in the center, for example, its pointer will no longer be useful. It must be redeclared before calling via the menu, but no checks are made for the add after and before (or rather it is unclear how those checks should be implemented). This is because the make empty class has no access to that iterator. It would be possible to check for the iterator being out of the space/passed the list tail/head, but this seems very verbose and unnecessary. Plus, it is innefficient. Depending on that implementation, it will fail in that case. I have not found an elegant way to solve this issue other than this. Additionally, because some may find it unclear how to implement the check case for this situation, we may find this solution is valid and more clear.
Let me know what I'm likely missing.