... 最简单但并非最好的实现迭代器的方法是在实现该ADT的类中定义的迭代器方法,call这样的迭代器为内部迭代器(internal iterator),这时,可以定义一个实现两个接口的类(命名为ListWithInternalIterator),如:BaseicIteratorInterface舆ListInterface。
基于24个网页-相关网页
该清单展示了内部迭代器(也称为push迭代器,因为它将每个元素依次推到代码块中)。
This listing illustrates an internal iterator (also known as a push iterator because it pushes each element in turn to the code block).
但是向后移动要复杂些,因为迭代器内部执行的是深度优先算法,预先排好了Rope遍历的顺序,需要访问每个叶节点。
But moving backward is more complicated, because internally the iterator performs a depth-first, preorder traversal of the Rope, visiting each of its leaf nodes.
迭代器模式:提供一种方法顺序访问一个聚合对象中的各个元素,而又不暴露其内部的表示。
The Iterator Pattern:provides a way to access the elements of an aggregate object sequentially without exposing its underying representation.
应用推荐