44 lines
822 B
C
44 lines
822 B
C
#include "General.h"
|
|
|
|
void InsertToBinaryTree(BinaryTree ** root, int k)
|
|
{
|
|
if (root == NULL)
|
|
{
|
|
MakeBinaryTree(root);
|
|
(*root)->info.int_ = k;
|
|
}
|
|
else if ((*root)->info.int_ > k)
|
|
{
|
|
if ((*root)->left == NULL)
|
|
{
|
|
AddLeftAfterBinaryTree(*root);
|
|
(*root)->left->info.int_ = k;
|
|
}
|
|
else
|
|
{
|
|
InsertToBinaryTree(&((*root)->left), k);
|
|
}
|
|
}
|
|
else if ((*root)->info.int_ < k)
|
|
{
|
|
if ((*root)->right == NULL)
|
|
{
|
|
AddRightAfterBinaryTree(*root);
|
|
(*root)->right->info.int_ = k;
|
|
}
|
|
else
|
|
{
|
|
InsertToBinaryTree(&((*root)->right), k);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
printf("Duplicate!\n");
|
|
}
|
|
}
|
|
|
|
void main(void)
|
|
{
|
|
BinaryTree * bt;
|
|
|
|
} |