using int Counter() { return counter; } }

using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace MvcTreeView{    public class BinaryTreeSubClass    {        public int counter;        public BinaryTree_Node roots;        public BinaryTreeSubClass()        {            counter = 0;            roots = null;        }        public void DeleteNode(int x)        {            BinaryTree_Node deleteNode = new BinaryTree_Node(x);            deleteNode.DeleteNode(roots, deleteNode);        }        public bool isRootEmpty()        {            return roots == null;        }        public void insert_Node(int d)        {            if (isRootEmpty())            {                roots = new BinaryTree_Node(d);            }            else            {                roots.insertData(ref roots, d);            }            counter++;        }        public bool search(int s)        {            return roots.search(roots, s);        }        public bool isLeaf()        {            if (!isRootEmpty())                return roots.isLeaf(ref roots);            return true;        }        public void display()        {            if (!isRootEmpty())                roots.display(roots);        }        public int Counter()        {            return counter;        }           }    private class BinaryTree_Node    {        private int number;        public BinaryTree_Node rightLeaf;        public BinaryTree_Node leftLeaf;        public BinaryTree_Node(int value)        {            number = value;            rightLeaf = null;            leftLeaf = null;        }        public bool isLeaf(ref BinaryTree_Node node)        {            return (node.rightLeaf == null && node.leftLeaf == null);        }        public void insertData(ref BinaryTree_Node node, int data)        {            if (node == null)            {                node = new BinaryTree_Node(data);            }            else if (node.number < data)            {                insertData(ref node.rightLeaf, data);            }            else if (node.number > data)            {                insertData(ref node.leftLeaf, data);            }        }        public bool search(BinaryTree_Node 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;        }        public void display(BinaryTree_Node n)        {            if (n == null)                return;            display(n.leftLeaf);            Console.Write(” ” + n.number);            display(n.rightLeaf);        }        public BinaryTree_Node DeleteNode(BinaryTree_Node root, BinaryTree_Node deleteNode)        {            if (deleteNode.number < root.number)            {                root.leftLeaf = DeleteNode(root.leftLeaf, deleteNode);            }            if (deleteNode.number > root.number)            {                root.rightLeaf = DeleteNode(root.rightLeaf, deleteNode);            }            if (deleteNode.number == root.number)            {                if (root.leftLeaf == null && root.rightLeaf == null)                {                    root = null;                    return root;                }                else if (root.leftLeaf == null)                {                    BinaryTree_Node temporary = root;                    root = root.rightLeaf;                    temporary = null;                }                else if (root.rightLeaf == null)                {                    BinaryTree_Node temporary = root;                    root = root.leftLeaf;                    temporary = null;                }            }            return root;        }        public class Tree        {            public int InsertShow()            {                BinaryTreeSubClass BT = new BinaryTreeSubClass();                BT.insert_Node(1); BT.insert_Node(6); BT.insert_Node(2); BT.insert_Node(4); BT.insert_Node(5); BT.insert_Node(3); BT.display(); BT.search(3);                return 1;            }        }    }}