예제 #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;
 }