二叉查找树
// 二叉查找树节点 Binary search tree node
public class BinarySearchTreeNode
{ public int key;// 二叉查找树节点的值
public BinarySearchTreeNode left;// 二叉查找树节点的左子节点
public BinarySearchTreeNode right;// 二叉查找树节点的右子节点
/// 二叉查找树节点构造函数
public BinarySearchTreeNode(int nodeValue)
{ key = nodeValue;//nodeValue 节点的值
left = null; right = null;
}
/// 插入节点
public void InsertNode(BinarySearchTreeNode node)
{ if(node.key > this.key)
{ if(this.right == null)
{ this.right = node;//node插入的节点
return;
}
else
this.right.InsertNode(node);
}
else
{ if(this.left == null)
{ this.left = node; return; }
else
this.left.InsertNode(node);
}
}
/// 二叉查找树查询
public bool SearchKey(int searchValue)
{ if(this.key == searchValue)//searchValue需要查询的值
return true;// 是否找到查询的值
if(searchValue > this.key)
{ if(this.right ==