# Binary Search Tree method question(s) C++!

**Question description**

These are not very difficult questions and i've already done most of the work I just want to know if my answers are correct or if you can fix them if they are not so please do not ask for more money..

I'm just trying to get a good grade here! Please help!

If anyone would be willing to help for free that would be greatly appreciated on my student budget! Hah :)

but if not it's okay I will still pay!

So first I had to write a method for the BinarySearchTree class named **sum** that takes no parameters. The method should return the total of
all the values in the tree and think recursively.

My answer:

int sum(node) if (node == NULL) { return 0; } else return node-->value + sum (node-->left) + sum (node-->right);

My next task was to

*w*rite a method for the BinarySearchTree class named

**height**that takes no parameters. The method should return the height of the tree and think recursively.

int BinarySearchTree::height (tree_node* count) { int l = 0; int r = 0; if (count == NULL) { return 0; } { l = height(count-->left); r = height(count-->right); if (l > r ||l == r) { return ( l +l ); } else { return ( r + l ); } }

And my last question was to write a method for the BinarySearchTree class named

**penultimate**that takes no parameters. The function should return the value of the second-largest item in the tree.

node* max = maximum(root); if(max --> left){ if (max-->parent-->date > max-->left-->date) cout << max-->parent-->data; else cout << max-->left-->data; } else cout << max-->parent-->data;

ANY SUGGESTIONS WOULD BE GREATLY APPRECIATED :)

THANKS!

## Tutor Answer

## Review from our student for this Answer

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors