binary tree
binary tree
h>
#include <stdlib.h>
/* A binary tree node has data, pointer to left child and a pointer to right child
*/
struct node
{
int data;
struct node* left;
struct node* right;
};
/* Compute the "maxDepth" of a tree -- the number of nodes along the longest path
from the root node down to the farthest leaf node.*/
/* Helper function that allocates a new node with the given data and NULL left and
right pointers. */
return (node);
}
// Helper function for getLevel(). It returns level of the data if data is present
in tree, otherwise returns 0.
if (node->data == data)
return level;
int main()
{
struct node* root = newNode(3);
root->left = newNode(2);
root->right = newNode(5);
root->left->left = newNode(1);
root->left->right = newNode(4);
getchar();
return 0;
}