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

Dec 10th, 2013
HelloWorld
Category:
Programming
Price: \$5 USD

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..

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.

```int sum(node)
if (node == NULL)

{
return 0;

}

else

return node-->value + sum (node-->left) + sum (node-->right);```

My next task was to write 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!
```

(Top Tutor) Daniel C.
(997)
School: Carnegie Mellon University

Studypool has helped 1,244,100 students

## Review from our student for this Answer

Sigchi4life
Dec 13th, 2013
"Thanks for the help. "

1822 tutors are online

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