日期:2014-05-16 浏览次数:20734 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BinaryTree
{
public class Tree<TItem>:IEnumerable<TItem> where TItem : IComparable<TItem>
{
public Tree(TItem nodeValue)
{
this.NodeData = nodeValue;
this.LeftTree = null;
this.RightTree = null;
}
public void Insert(TItem newItem)
{
TItem currentNodeValue = this.NodeData;
if (currentNodeValue.CompareTo(newItem) > 0)
{
if (this.LeftTree == null)
{
this.LeftTree = new Tree<TItem>(newItem);
}
else
{
this.LeftTree.Insert(newItem);
}
}
else
{
if (this.RightTree == null)
{
this.RightTree = new Tree<TItem>(newItem);
}
else
{
this.RightTree.Insert(newItem);
}
&nb