using System.Collections.Generic;
using System.Text;
namespace BinarySearchTree
{
internal class Node
{
private T _data;
private Node
private Node
internal Node(T data)
{
_data = data;
}
internal Node
{
get
{
return leftNode;
}
set
{
leftNode = value;
}
}
internal Node
{
get
{
return rightNode;
}
set
{
rightNode = value;
}
}
internal int CompareTo(T val)
{
return _data.CompareTo(val);
}
}
}
----------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace BinarySearchTree
{
public class BinarySearchTree
{
private Node
public BinarySearchTree()
{
}
public void Insert(T val)
{
rootNode = Insert(rootNode, val);
}
private Node
{
if (node == null)
{
node = new Node
return node;
}
if (node.CompareTo(val) >= 0)
{
node.LeftNode = Insert(node.LeftNode, val);
}
else
{
node.RightNode = Insert(node.RightNode, val);
}
return node;
}
}
}
----------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace BinarySearchTree
{
class Program
{
static void Main(string[] args)
{
BinarySearchTree
bns.Insert(3);
bns.Insert(2);
bns.Insert(10);
bns.Insert(1);
bns.Insert(4);
bns.Insert(11);
}
}
}
No comments:
Post a Comment