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); }
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); }
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); }