2017-07-14 11:24:11 +03:00
|
|
|
/* Includes the functions for Recursive Traversals
|
|
|
|
of a Binary Tree. It is assumed that nodes and
|
|
|
|
tree have been created as per create_node.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
void inOrderTraversal(struct node *node)
|
|
|
|
{
|
2020-06-28 18:25:37 +03:00
|
|
|
if (node == NULL) // if tree is empty
|
2017-07-14 11:24:11 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
inOrderTraversal(node->leftNode);
|
|
|
|
printf("\t%d\t", node->data);
|
|
|
|
inOrderTraversal(node->rightNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void preOrderTraversal(struct node *node)
|
|
|
|
{
|
2020-06-28 18:25:37 +03:00
|
|
|
if (node == NULL) // if tree is empty
|
2017-07-14 11:24:11 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
printf("\t%d\t", node->data);
|
|
|
|
preOrderTraversal(node->leftNode);
|
|
|
|
preOrderTraversal(node->rightNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void postOrderTraversal(struct node *node)
|
|
|
|
{
|
2020-06-28 18:25:37 +03:00
|
|
|
if (node == NULL) // if tree is empty
|
2017-07-14 11:24:11 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
postOrderTraversal(node->leftNode);
|
|
|
|
postOrderTraversal(node->rightNode);
|
2020-05-29 23:23:24 +03:00
|
|
|
printf("\t%d\t", node->data);
|
2017-07-14 11:24:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
/* traversals can be done by simply invoking the
|
|
|
|
function with a pointer to the root node.
|
|
|
|
*/
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
return 0;
|
2017-07-14 11:24:11 +03:00
|
|
|
}
|