I don't know I think maybe calling root is. If I can't fix this I'll
post the header and both master source files so no one will have to go
back and look at anything.
-----
build.c
#include "node.h"
int find(struct node *node, int target)
{
if (node == NULL) {
return (1);
} else {
if (target == node->count) {
return (0);
} else {
if (target < node->count) {
return (find(node->right, target)
);
} else
return (find(node->left, target)
);
}
}
}
struct node *newNode(int count)
{
struct node *node = malloc(sizeof(struct node));
node->right = NULL;
node->left = NULL;
node->count = count;
return (node);
}
struct node *insert(struct node *node, int count)
{
if (node == NULL) {
return (newNode(count));
} else {
if (count <= node->count)
node->left = insert(node->left, count);
else
node->right = insert(node->right, count);
return (node);
}
}
build2.c
#include "node.h"
struct node *build(void)
{
struct node *root = NULL;
root = (struct node *) insert(root, 2);
root = (struct node *) insert(root, 1);
root = (struct node *) insert(root, 3);
return (root);
};
int maxDepth(struct node *node)
{
if (node == NULL) {
return 0;
}
else {
int ldepth = maxDepth(node->left);
int rdepth = maxDepth(node->right);
if (ldepth > rdepth)
return (ldepth + 1);
else
return (rdepth + 1);
}
}
main.c
#include "node.h"
int main()
{
struct node *root;
int i = maxDepth(root);
printf("%i\n", i);
return 0;
}
I'll keep working on this anyway.
Bill