Collection Iterator
来源:互联网 发布:html5 360全景源码 编辑:程序博客网 时间:2024/06/05 12:48
// Collection is an interfacepublic interface Collection<E> { boolean add(E element); Iterator<E> iterator(); ... }public interface Iterator<E> { E next(); boolean hasNext(); void remove();}
public class MergeIterator {Iterator<Integer> left;Iterator<Integer> right;int lastLeft;int lastRight;boolean leftNotUsed;public MergeIterator (Iterator<Integer> left, Iterator<Integer> right) {this.left = left;this.right = right;if (left.hasNext()) {lastLeft = left.next();leftNotUsed = true;} else if (right.hasNext()) {lastRight = right.next();leftNotUsed = false;} }public boolean hasNext() {return left.hasNext() | right.hasNext();}public int next() throws Exception {if (!left.hasNext() && !right.hasNext()) {throw new Exception(" ");}if (left.hasNext() && !right.hasNext()) {if (leftNotUsed) {leftNotUsed = false;return lastLeft;}return left.next();}if (!left.hasNext() && right.hasNext()) {if (leftNotUsed) {leftNotUsed = false;return lastLeft;}return right.next();}if (leftNotUsed) {lastRight = right.next();if (lastLeft < lastRight) {leftNotUsed = false;return lastLeft;} else {return lastRight;}} else {lastLeft = left.next();if (lastRight < lastLeft) {leftNotUsed = true;return lastRight;} else {leftNotUsed = false;return lastLeft;}}}}
0 0
- Collection Iterator
- Collection 与iterator接口
- Collection(二)Iterator
- java--collection和Iterator
- Iterator && Iterable Collection && Map
- Collection与Iterator
- Collection 和 Iterator
- Java Collection Iterable Iterator
- Collection和Iterator接口
- Collection接口和Iterator接口
- Collection和Iterator学习笔记
- Collection、Iterator接口、foreach循环
- 用iterator接口遍历collection
- Java集合Collection与Iterator
- mx.utils 包 之Collection&Iterator
- Cannot create iterator for this collection 问题解决
- 集合(Collection)与迭代器(Iterator)
- Cannot create iterator for this collection
- 关于Android横竖屏布局
- 思考c++中rand()函数产生随机数需不需要srand()的发现
- Frenquency == 4
- 电感 电容耦合的判断
- Remove Element
- Collection Iterator
- 【java初学笔记1】关于继承的一些要点
- 和安全有关的那些事(非对称加密、数字摘要、数字签名、数字证书、SSL、HTTPS及其他)
- 设计模式(C++版)之(prototype) 原型模式
- OpenRISC和Orpsoc在DE2-115上的的bootup实验
- Roman to Integer
- 实现3个按钮的回调函数
- 标准系统安装60
- Swap Nodes in Pairs