this is my height function in bst. cpp

```
int IntBinaryTree::getHeight(TreeNode * nodePtr)
{
if(nodePtr = NULL)
return 0;
else
return (max(1+getHeight(nodePtr->left), 1+getHeight(nodePtr->right)));
}
```

When I call it in main(). I got an error.

this is my main()

```
int main {
IntBinaryTree tree;
....
tree. getHeight();
return 0;
}
```

You didn't say what error, but looks like changing:

```
if(nodePtr = NULL)
```

to

```
if(nodePtr == NULL)
^^
```

is what you need.

Similar Questions

Im working on a binary search tree program and I am trying to find the successor of a node given its data. I am following psuedocode and feel like I am doing it correctly, but clearly I am not because

I'm having trouble writing code to determine if certain data is present in my tree, this is the BinaryTreeNode class class BinaryTreeNode { public: Data * nodeData; BinaryTreeNode * left; BinaryTreeNo

I want to find minimum value in a Binary Search Tree. I have written below code. But when i call the function from main and I pribt the return value, it is printing as 0 always. cal you please help. i

hi i have implemented a bst in mips and i need to print this tree. Each node has following four information its value parent's address left child's address right child's address i should print the t

I am stucked on this simple binary search tree very long as my main problem is that the (BST * bst) in function bst_get() is NULL. typedef struct { char *key; void *value; } KVP; typedef struct bst {

If I am attempting to minimize the height of a Binary Search Tree, are these the correct steps?: 1) produce a sorted array from the tree 2) reconstruct the tree by adding the sorted elements into the

How wil you convert Binary Tree to Binary Search Tree with O(1) extra space ?

I'm studying Java data structures and algorithms in college and we have come across the topic of binary search trees and tree transversal but I don't see the purpose of these topics in my programming.

Ok, I am trying to get a binary search tree to balance, and I know why it's not working, but I don't know how to fix it. This is what I have for my balancing methods. public void balance(){ if(isEmpt

and I was trying to implement a binary searching tree: template <typename T> bool Tree<T>::search(TreeNode<T> *ptr, const T &key) { if (ptr == 0) { cout<<No such data: &l

I've been trying to write a recursive string method for a binary search tree that returns a multiple line representation of a tree with preorder path info. Each node should be prefaced by a series of

I wrote this recursive function, which works as expected. It validates a binary tree i.e., it checks whether the given binary tree is a binary search tree or not and gives the correct answer too. Howe

I'm currently having difficulty inserting a node into a binary tree using recursion. I've been dwelling on this problem for a few days now and thought it was time I came looking for answers! Node clas

Is there a method to build a balanced binary search tree? Example: 1 2 3 4 5 6 7 8 9 5 / \ 3 etc / \ 2 4 / 1 I'm thinking there is a method to do this, without using the more complex self-balancing t

So, the question is to find the largest sub-tree (the largest sub-tree is the node with maximum size) in a binary tree which is a BST. I found the following website which enlists an algorithm. http://

For inorder binary search tree traversal there is an iterative algorithm that uses no auxiliary memory (stack, parent pointers, visited flags) known as Morris Traversal. Is there a similar algorithm f

We all know that a hash table has O(1) time for both inserts and look-ups if the hash function was well chosen. So, what are the reason we want to use Binary Search Tree? Just because a perfect hash f

I want to write the algorithm of Balanced Binary Search Tree with backtracking would you please guild me about it? I dont know how should I implement it. I dont want any code I need just explanation.

Is the depth of a node in a Binary Search Tree (BST) the same as it's distance from the root? I think so, but I'm not certain. I believe distance is the concept of trees in general and depth is that c

I've been stuck on the insertion part of the binary search tree. I get so confused with nested structs. The basic idea of this program is to create a bst that is able to hold names and double values w

I have two methods to get min and max height of a binary tree in Java. But I am doing two traversals through the root two times. each is log n in Big(O). Is there a way to compute both min and max in

I am getting an stack overflow when the program tries to add a number. It seems to be accessing a nonexistent binary search tree. Here is the error code: Unhandled exception at 0x01084DD9 in CIS 350 q

I'm having trouble interpreting a certain question about inserting elements to a binary search tree. I'm familiar with preorder, postorder, and inorder traversals, but I'm unfamiliar with the followin

What is the name of the binary tree (or the family of the binary trees), that is balanced, and has the minimum number of nodes possible for its height? Well this is special kind of tree not the AVL tr

I'm working on a problem which requires me to copy a binary search tree recursively and to return the tree. I am coding in the binary search tree class, so it will copy whatever binary search tree it

I need to build a balanced binary search tree. So far my program inserts the numbers from 1 to 26, but my program does not build it into a balanced binary search tree. If anyone could look at my code

I'm implementing an AVL Tree (a self-balancing Binary Search Tree) in PHP and have things working pretty normally. I have in-order, pre-order, and level-order iterators working, but I can't figure out

I'm getting a segmentation fault with my code and I'm not sure why. I'm trying to find the max value in a regular binary tree that is not ordered. tnode<int> *maxT(tnode<int> *t) { if (t =

In preparation for the data structures midterm, the professor gave us last year's test, one question which deals with re-arranging an example tree into a complete binary search tree. I've tried severa

I need a general formula to calculate the minimum height of the binary tree and the maximum height of the binary tree. (not the binary search tree)

Im trying to create an insertion function on an binary search tree. I looked at other questions here but they re not like my problem. I can compile it but it crashes on the commented line below: void

I want to convert a sorted integer array into a binary search tree. I believe I understand how to do this. I have posted my pseudo-code below. What I cannot picture is how the recursion actually works

Im trying to insert into an array Based Binary Search tree. I am not sure how i prevent overwriting data using left and right indexes... Do i insert leftchild as tree[2 * i + 1] and rightchild as tre

I am trying to write a function to get the height of a binary tree. When I print the value of the maxi the value is what I expect but when the function returns the value, the value is always 0. Can so

Disclaimer: This is for an assignment. I am not asking for explicit code answers, only help understanding why my code isn't working. I am trying to implement a basic Binary Search Tree, but I am havin

According to what explained in wiki I think dfs on a binary tree is the same one with preorder traversal root--left--right.(am i right?) But just did a little search and got this code, and the author

Today, in class my professors said there's a balance binary search tree which I never heard of it before. I would like to know is there a Balance Binary Search tree without rotation? From my understan

I want to implement an algorithm that inserts sorted arrays into binary search trees but I don't want ending up with a tree that only grows to one side. Do you have any ideas? Thanks.

I am supposed to write a method that takes in two integers as a min and max. Then it removes any integers from the tree that are less than the minimum and larger than the maximum. The code I have so f

In a school assignment I'm supposed to complete a method that should return an array of node elements in ascendig order. The nodes are assembled in a binary search tree, so to sort them correct, I got

I know the recursive code could be written for finding the minimum height. But for a very large tree (like million nodes in leftside vs 1 node in right side) - the approach isn't good. So please let m

Im trying to build an array based, Binary Search Tree by following the algorithm at: http://highered.mcgraw-hill.com/olcweb/cgi/pluginpop.cgi?it=gif%3A:600%3A:388%3A%3A/sites/dl/free/0070131511/2532

I want to implement a binary tree such that it does not include duplicates. Here's my insert() method. public BinaryNode insert(BinaryNode node, int x) { if (node == null) { node = new BinaryNode(x);

Is there a way you can have a Binary Search Tree with Object nodes, that store multiple values, and which have the ability to treat one of these values as the main variable that will be used for com

Under what circumstances would it be better to implement a Dictionary ADT using a balanced binary search tree rather than a hash table? My assumption was that it is always better to use a binary searc

I am working on a function that searches through a binary search tree in C for a name that is passed in with the function. However, I am stuck on how to format my loop so that the recusion doesn't sim

Im having trouble with a method that finds the height of the closest leaf. What i have just counts all of the leafs. would i have to separate the recursive calls into two conditional statements to che

I came across a problem stating For each node in a binary search tree, create a new duplicate node, and insert the duplicate as the left child of the original node. The resulting tree should still be

I'm getting a problem with my display functions dealing with binary search trees. The main problem I'm having is getting the count variable to increment correctly in the recursive function so that I c

So I'm working on a method that gets the number of nodes in a binary search tree, when I have 3 nodes, it gives me 3, but if I do 5 it gives me 4, what do I need to change? int BinaryTree::size(int co