public class TreeNode
{
public TreeNode Left;
public TreeNode Right;
public int Data { get; set; }
public TreeNode(int data)
{
Left = null;
Right = null;
Data = data;
}
}
public class BinarySearchTree
{
private TreeNode _root;
public BinarySearchTree()
{
_root = null;
}
public void Insert(int data)
{
TreeNode tempNode = null;
Insert(_root, tempNode);
}
private void Insert(TreeNode treeNode, TreeNode newNode)
{
newNode = new TreeNode(3);
treeNode = new TreeNode(4);
}
在这个例子中,public voidInsert(int data)
方法基本上只是调用了私有方法,我在方法的末尾设置了一个断点public void Insert(int data)
。
并且通知_root
仍然为空,并且tempNode
是4。我不明白为什么?谁能解释一下?