zoukankan      html  css  js  c++  java
  • 251. Flatten 2D Vector

    提示一大堆,也没看懂。
    只要2个Iter就行了,iter1是大LIST的iterator,iter2只能是小sub-list的(这里使用了排除法...)

    换句话说,iter2是iter1的iterator。。

    iter2没NEXT()的时候,iter1 goes to next..

    最大的问题是解决空集的问题。。

    sub-list可以是空,但是最后结果不能包含NULL,所以加一层判断。。

    public class Vector2D implements Iterator<Integer> {
    
    
        Iterator iter = null;
        Iterator iter2 = null;
        public Vector2D(List<List<Integer>> vec2d) 
        {
            if(vec2d.size() != 0)
            {
                iter = vec2d.iterator();
            }
        }
    
        @Override
        public Integer next() 
        {
    
            return (Integer)iter2.next();
        }
    
        @Override
        public boolean hasNext() 
        {   
            if(iter == null) return false;
            if(iter2 == null || !iter2.hasNext())
            {
                while(iter.hasNext())
                {
                    List<Integer> tempList = (List<Integer>)iter.next();
                    if(tempList.size() != 0)
                    {
                        iter2 = tempList.iterator();
                        return true;
                    }
                }
                return false;
            }
            else return true;
        }
    }
    
    /**
     * Your Vector2D object will be instantiated and called as such:
     * Vector2D i = new Vector2D(vec2d);
     * while (i.hasNext()) v[f()] = i.next();
     */
    
  • 相关阅读:
    Twain文档链接
    JavaScript 事件绑定函数
    VC++ 字符串Dword、LPSTR、LPWSTR、LPCSTR、LPCWSTR、LPTSTR、LPCTSTR
    Sciter参考资料
    C++对windows控制面板的操作
    C++ Msi函数判断应用是否已经安装
    WMware 安装 Mac OSX
    C++文件流操作
    jquery弹出层
    CSS3 水平翻转
  • 原文地址:https://www.cnblogs.com/reboot329/p/5962685.html
Copyright © 2011-2022 走看看