58 lines
1.2 KiB
C
58 lines
1.2 KiB
C
#include "General.h"
|
|
|
|
void PreodererPrintBinaryTree(BinaryTree * root, void print(Data_Type))
|
|
{
|
|
if (root != NULL)
|
|
{
|
|
print(root->info);
|
|
PreodererPrintBinaryTree(root->left, print);
|
|
PreodererPrintBinaryTree(root->right, print);
|
|
}
|
|
}
|
|
|
|
void PosorderPrintBinaryTree(BinaryTree * root, void print(Data_Type))
|
|
{
|
|
if (root != NULL)
|
|
{
|
|
PosorderPrintBinaryTree(root->left, print);
|
|
PosorderPrintBinaryTree(root->right, print);
|
|
print(root->info);
|
|
}
|
|
}
|
|
|
|
void InorderPrintBinaryTree(BinaryTree * root, void print(Data_Type))
|
|
{
|
|
if (root != NULL)
|
|
{
|
|
InorderPrintBinaryTree(root->left, print);
|
|
print(root->info);
|
|
InorderPrintBinaryTree(root->right, print);
|
|
}
|
|
}
|
|
|
|
void LevelPrintBinaryTree(BinaryTree * root, void print(Data_Type))
|
|
{
|
|
BinaryTree * temp;
|
|
queue * qt;
|
|
InitQueue(qt);
|
|
InsertQueue(qt, ((Data_Type)root));
|
|
while (IsEmptyQueue(qt))
|
|
{
|
|
temp = (BinaryTree *)RemoveQueue(qt).pointer;
|
|
if (!temp->left)
|
|
{
|
|
InsertQueue(qt, ((Data_Type)temp->left));
|
|
}
|
|
print(temp->info);
|
|
if (!temp->right)
|
|
{
|
|
InsertQueue(qt, ((Data_Type)temp->right));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void main(void)
|
|
{
|
|
|
|
} |