Exemplo n.º 1
0
        public bool HasNext()
        {
            if (_curIndex >= _nestedList.Count)
            {
                return(false);
            }

            if (_nestedList[_curIndex].IsInteger())
            {
                return(true);
            }
            else
            {
                EnsureSubnestedIterator();
                if (!_subNestedIterator.HasNext())
                {
                    _curIndex++;
                    _subNestedIterator = null;
                }
                else
                {
                    return(true);
                }

                return(HasNext());
            }
        }
Exemplo n.º 2
0
 private void EnsureSubnestedIterator()
 {
     if (_subNestedIterator == null)
     {
         _subNestedIterator = new NestedIterator(_nestedList[_curIndex].GetList());
     }
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            // [[1,1],2,[1,1]]
            var nestedIntegerList = new List <NestedInteger>
            {
                new NestedIntegerImpl
                {
                    IsInteger = false,
                    List      = new List <NestedInteger>
                    {
                        new NestedIntegerImpl
                        {
                            IsInteger = true,
                            Integer   = 1
                        },
                        new NestedIntegerImpl
                        {
                            IsInteger = true,
                            Integer   = 1
                        }
                    }
                },
                new NestedIntegerImpl
                {
                    IsInteger = true,
                    Integer   = 2
                },
                new NestedIntegerImpl
                {
                    IsInteger = false,
                    List      = new List <NestedInteger>
                    {
                        new NestedIntegerImpl
                        {
                            IsInteger = true,
                            Integer   = 1
                        },
                        new NestedIntegerImpl
                        {
                            IsInteger = true,
                            Integer   = 1
                        }
                    }
                }
            };

            var iterator = new NestedIterator(nestedIntegerList);

            while (iterator.HasNext())
            {
                Console.WriteLine(iterator.Next());
            }
        }
Exemplo n.º 4
0
        public int Next()
        {
            if (_nestedList[_curIndex].IsInteger())
            {
                var result = _nestedList[_curIndex].GetInteger();
                _curIndex++;
                return(result);
            }
            EnsureSubnestedIterator();

            if (_subNestedIterator.HasNext())
            {
                return(_subNestedIterator.Next());
            }
            else
            {
                _curIndex++;
                _subNestedIterator = null;
                return(Next());
            }
        }