Esempio n. 1
0
        public List <T> LevelOrderList()
        {
            List <T> items = new List <T>();
            ZQueue <ZBinaryTreeNode <T> > que = new ZQueue <ZBinaryTreeNode <T> >();

            if (Root != null)
            {
                items.Add(Root.Value);
                if (Root.LeftNode != null)
                {
                    que.Enqueue(Root.LeftNode);
                }
                if (Root.RightNode != null)
                {
                    que.Enqueue(Root.RightNode);
                }
            }

            while (que.Count > 0)
            {
                ZBinaryTreeNode <T> node = que.Dequeue();
                items.Add(node.Value);
                if (Root.LeftNode != null)
                {
                    que.Enqueue(Root.LeftNode);
                }
                if (Root.RightNode != null)
                {
                    que.Enqueue(Root.RightNode);
                }
            }

            return(items);
        }
Esempio n. 2
0
        public ZBinaryTreeNode <T> Search(T data)
        {
            ZBinaryTreeNode <T>           match = null;
            ZQueue <ZBinaryTreeNode <T> > que   = new ZQueue <ZBinaryTreeNode <T> >();

            if (Root != null)
            {
                if (data.Equals(Root.Value))
                {
                    return(Root);
                }

                if (Root.LeftNode != null)
                {
                    que.Enqueue(Root.LeftNode);
                }
                if (Root.RightNode != null)
                {
                    que.Enqueue(Root.RightNode);
                }
            }

            while (que.Count > 0)
            {
                ZBinaryTreeNode <T> node = que.Dequeue();
                if (data.Equals(node.Value))
                {
                    return(node);
                }

                if (Root.LeftNode != null)
                {
                    que.Enqueue(Root.LeftNode);
                }
                if (Root.RightNode != null)
                {
                    que.Enqueue(Root.RightNode);
                }
            }

            return(match);
        }
Esempio n. 3
0
        public int CountFullNodes()
        {
            int total = 0;
            ZQueue <ZBinaryTreeNode <T> > que = new ZQueue <ZBinaryTreeNode <T> >();

            if (Root != null)
            {
                if (Root.LeftNode != null && Root.RightNode != null)
                {
                    total++;
                }

                if (Root.LeftNode != null)
                {
                    que.Enqueue(Root.LeftNode);
                }
                if (Root.RightNode != null)
                {
                    que.Enqueue(Root.RightNode);
                }
            }

            while (que.Count > 0)
            {
                ZBinaryTreeNode <T> node = que.Dequeue();
                if (Root.LeftNode != null && Root.RightNode != null)
                {
                    total++;
                }

                if (Root.LeftNode != null)
                {
                    que.Enqueue(Root.LeftNode);
                }
                if (Root.RightNode != null)
                {
                    que.Enqueue(Root.RightNode);
                }
            }
            return(total);
        }