void first_visit(node *current)//前序遍历
{
printf("%d ",current->entry);
if (current->left != NULL) first_visit(current->left);
if (current->right != NULL) first_visit(current->right);
}
void last_visit(node *current)//后序遍历
{
if (current->left != NULL) first_visit(current->left);
if (current->right != NULL) first_visit(current->right);
printf("%d ",current->entry);
}
void middle_visit(node *current)//中序遍历
{
if (current->left != NULL) first_visit(current->left);
printf("%d ",current->entry);
if (current->right != NULL) first_visit(current->right);
}
/*
从代码来看,很好的对应了每种遍历方式的名称,前序遍历是先输出当前结点,再尝试访问左结点和右结点,就是输出语句的位置在之前,中间和之后
*/
{
printf("%d ",current->entry);
if (current->left != NULL) first_visit(current->left);
if (current->right != NULL) first_visit(current->right);
}
void last_visit(node *current)//后序遍历
{
if (current->left != NULL) first_visit(current->left);
if (current->right != NULL) first_visit(current->right);
printf("%d ",current->entry);
}
void middle_visit(node *current)//中序遍历
{
if (current->left != NULL) first_visit(current->left);
printf("%d ",current->entry);
if (current->right != NULL) first_visit(current->right);
}
/*
从代码来看,很好的对应了每种遍历方式的名称,前序遍历是先输出当前结点,再尝试访问左结点和右结点,就是输出语句的位置在之前,中间和之后
*/