using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace MvcTreeView{ public class Node_BinaryTree { public bool searching( int s,Node_BinaryTree tree) { if (tree == null) return false; if (tree.number == s) { return true; } else if (tree.number < s) { return searching(s, tree.rightLeaf); } else if (tree.number > s) { return searching(s, tree.leftLeaf); } return false; } public Node_BinaryTree rightLeaf; public Node_BinaryTree leftLeaf; public int number; public Node_BinaryTree(int value) { rightLeaf = null; leftLeaf = null; number = value; } public bool isLeaf(ref Node_BinaryTree node) { return (node.rightLeaf == null && node.leftLeaf == null); } public void insertData(ref Node_BinaryTree node, int data) { if (node == null) { node = new Node_BinaryTree(data); } else if (node.number < data) { insertData(ref node.rightLeaf, data); } else if (node.number > data) { insertData(ref node.leftLeaf, data); } } public void display(Node_BinaryTree n) { if (n == null) return; display(n.leftLeaf); Console.Write(” ” + n.number); display(n.rightLeaf); } public Node_BinaryTree DeleteNode(Node_BinaryTree root, Node_BinaryTree 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) { Node_BinaryTree temporary = root; root = root.rightLeaf; temporary = null; } else if (root.rightLeaf == null) { Node_BinaryTree 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; } } public class BinaryTreeSubClass { public int counter; public Node_BinaryTree roots; public BinaryTreeSubClass() { counter = 0; roots = null; } public void DeleteNode(int x) { Node_BinaryTree deleteNode = new Node_BinaryTree(x); deleteNode.DeleteNode(roots, deleteNode); } public bool isRootEmpty() { return roots == null; } public void insert_Node(int d) { if (isRootEmpty()) { roots = new Node_BinaryTree(d); } else { roots.insertData(ref roots, d); } counter++; } public bool search(int s) { return roots.searching(s,roots); } 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; } } }}