【发布时间】:2016-09-23 12:26:16
【问题描述】:
如何在树中插入 1 到 10000 之间的随机整数?我只是在下面的代码中使用scanner.in
private BinaryTree insert(BinaryTree node, int value)
{
if (node == null)
node = new BinaryTree(value);
else
{
if (value <= node.getValue())
node.left_child = insert(node.left_child, value);
else
node.right_child = insert(node.right_child, value);
}
return node;
}
public static void main(String[] args)
do
{
//tree operations
System.out.println("\nTree Operations\n");
System.out.println("1. insert ");
int choice = scan.nextInt();
switch (choice)
{
case 1 :
System.out.println("get integer element to insert");
bst.insert( scan.nextInt() );
break;
default :
System.out.println("Wrong Entry \n ");
break;
}
【问题讨论】:
-
到底是什么问题?你有错误吗?结果错误?
-
我认为您需要重新考虑如何实施 BT
标签: java algorithm data-structures binary-tree insertion