ツリーに1から10000までのランダムな整数を挿入する方法は?私はこれがちょうど挿入のために、あなたはそれがバランスするために別のプロセスが必要であるバイナリツリーを実装してバランスを取る
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無効メイン(文字列[] 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;
}
問題はなんですか?エラーが発生していますか?間違った結果ですか? – Mureinik
あなたはあなたのBTを実装する方法を再考する必要があると思います –