First Upload
This commit is contained in:
44
25 - Trees/ex1.c
Normal file
44
25 - Trees/ex1.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#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;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user