Question: //main.cpp #include #include treeNode.h using namespace std; int main() { TreeNode n1, n2, n3, n4; n1.left = &n2; n1.right = &n3; n2.left = &n4; cout

 //main.cpp #include #include "treeNode.h" using namespace std; int main() { TreeNode

//main.cpp

#include

#include "treeNode.h"

using namespace std;

int main() {

TreeNode n1, n2, n3, n4;

n1.left = &n2;

n1.right = &n3;

n2.left = &n4;

cout

cout

cout

cout

return 0;

}

//treenode.cpp

#include "treeNode.h"

#include

#include

using namespace std;

TreeNode::TreeNode() : left(NULL), right(NULL) { }

int TreeNode::getHeight() {

return -1;

}

//treenode.h

#ifndef _TREENODE_H

#define _TREENODE_H

#include

#include

using namespace std;

class TreeNode {

public:

TreeNode *left;

TreeNode *right;

TreeNode();

int getHeight();

};

#endif

The Problem Complete the member function getHeight in the TreeNode class. This function must return the height of the binary tree. Example In main.cpp, a simple test case has been created with a simple binary tree: n1 n2 n3 n4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!