示例#1
0
        public void display(Node1 n)
        {
            if (n == null)
            {
                return;
            }

            display(n.leftLeaf);
            Console.Write(" " + n.number);
            display(n.rightLeaf);
        }
示例#2
0
        public void insert(int d)
        {
            if (isEmpty())
            {
                root = new Node1(d);
            }
            else
            {
                root.insertData(ref root, d);
            }

            count++;
        }
示例#3
0
        public void insertData(ref Node1 node, int data)
        {
            if (node == null)
            {
                node = new Node1(data);
            }
            else if (node.number < data)
            {
                insertData(ref node.rightLeaf, data);
            }

            else if (node.number > data)
            {
                insertData(ref node.leftLeaf, data);
            }
        }
示例#4
0
        public bool search(Node1 node, int s)
        {
            if (node == null)
            {
                return(false);
            }

            if (node.number == s)
            {
                return(true);
            }
            else if (node.number < s)
            {
                return(search(node.rightLeaf, s));
            }
            else if (node.number > s)
            {
                return(search(node.leftLeaf, s));
            }

            return(false);
        }
示例#5
0
 public bool isLeaf(ref Node1 node)
 {
     return(node.rightLeaf == null && node.leftLeaf == null);
 }
示例#6
0
 public Node1(int value)
 {
     number    = value;
     rightLeaf = null;
     leftLeaf  = null;
 }
示例#7
0
 public BinaryTree()
 {
     root  = null;
     count = 0;
 }