Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
创建了一个初步的实现,
迭代器这种工具由于是遍历,所以删除指支持到了删除当前元素。
然后接口设计的error,我觉得hasNext的方法如果返回error,用起来很麻烦,所以加了一个Err(),但是感觉很冗余
对于是否支持在迭代的时候修改元素,本质上还是一个冲突问题。
迭代器本质上关心的还是把元素给取出来遍历,如果需要在迭代器里面对原数据结构修改,我觉得应该是要对不同的数据结构进类型单独设计迭代器方法,而不是放到顶层接口中,如果在迭代的时候如果对原来的数据结构进行了修改,会导致数据不一致问题,结果很难预知,调用者也很难处理。我觉得这个时候应该需要终止迭代器,然后重新获取数组元素。