Esempio n. 1
0
        public bool MoveNext()
        {
            if (_current == null)
            {
                _current = this;
                return(true);
            }

            if (_current.Childs.Count > 0)
            {
                _queue.Push(_current);
                _current = _current.First;
            }
            else
            {
                _current = _current.NextSbiling;
                while (_current == null)
                {
                    if (_queue.Count <= 0)
                    {
                        return(false);
                    }
                    _current = _queue.Pop();
                    if (_current.Parent == null || _current.ID == this.ID)
                    {
                        return(false);
                    }

                    _current = _current.NextSbiling;
                }
            }
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// 在此节点前添加一个节点
        /// </summary>
        /// <param name="index">从0开始</param>
        /// <param name="node"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public ZTNode <T> InsertBefore(int index, T node, string id)
        {
            if (index < 0 || index >= this.Childs.Count)
            {
                return(this.AppendChild(node, id));
            }

            ZTNode <T> leaf = new ZTNode <T>(node, id);

            leaf.Parent = this;

            ZTNode <T> temp = this.Childs[index];

            leaf.m_PreSbiling = temp.m_PreSbiling;
            if (leaf.m_PreSbiling != null)
            {
                leaf.m_PreSbiling.m_NextSbiling = leaf;
            }

            leaf.m_NextSbiling = temp;
            leaf.m_NextSbiling.m_PreSbiling = leaf;


            this.Childs.Insert(index, leaf);

            return(leaf);
        }
Esempio n. 3
0
        /// <summary>
        /// 添加一个子节点
        /// </summary>
        /// <param name="node"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public ZTNode <T> AppendChild(T node, string id)
        {
            ZTNode <T> leaf = new ZTNode <T>(node, id);

            leaf.Parent = this;

            if (this.Childs.Count > 0)
            {
                leaf.m_PreSbiling = this.Childs[this.Childs.Count - 1];
                leaf.m_PreSbiling.m_NextSbiling = leaf;
            }

            this.Childs.Add(leaf);

            return(leaf);
        }
Esempio n. 4
0
 /// <summary>
 /// 通过ID得到节点
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public ZTNode <T> GetNodeByID(string id)
 {
     if (this.ID == id)
     {
         return(this);
     }
     for (int i = 0; i < this.Childs.Count; i++)
     {
         ZTNode <T> temp = this.Childs[i].GetNodeByID(id);
         if (temp != null)
         {
             return(temp);
         }
     }
     return(null);
 }
Esempio n. 5
0
        /// <summary>
        /// 从树中移除一个叶子节点
        /// </summary>
        /// <param name="node"></param>
        public bool RemoveChild(T node)
        {
            for (int i = 0; i < this.Childs.Count; i++)
            {
                if (this.Childs[i].Value == node)
                {
                    ZTNode <T> ztnode = this.Childs[i];

                    if (ztnode.m_PreSbiling != null)
                    {
                        ztnode.m_PreSbiling.m_NextSbiling = ztnode.m_NextSbiling;
                    }

                    if (ztnode.m_NextSbiling != null)
                    {
                        ztnode.m_NextSbiling.m_PreSbiling = ztnode.m_PreSbiling;
                    }
                    this.Childs.RemoveAt(i);
                }
            }
            return(false);
        }
Esempio n. 6
0
        /// <summary>
        /// 从树中移除一个叶子节点
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool RemoveChild(string id)
        {
            for (int i = 0; i < this.Childs.Count; i++)
            {
                if (this.Childs[i].ID == id)
                {
                    ZTNode <T> ztnode = this.Childs[i];

                    if (ztnode.m_PreSbiling != null)
                    {
                        ztnode.m_PreSbiling.m_NextSbiling = ztnode.m_NextSbiling;
                    }

                    if (ztnode.m_NextSbiling != null)
                    {
                        ztnode.m_NextSbiling.m_PreSbiling = ztnode.m_PreSbiling;
                    }
                    this.Childs.RemoveAt(i);
                }
            }

            return(true);
        }
Esempio n. 7
0
 public void Reset()
 {
     _current = null;
 }