MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / heightdiameter

Function heightdiameter

CPP/binarytreeuse.cpp:203–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

201}
202
203pair<int,int> heightdiameter(binarytree<int>*root)
204{
205 if(root==NULL)
206 {
207 pair<int,int> p;
208 p.first=0;
209 p.second=0;
210 return p;
211 }
212
213 pair<int,int> leftans=heightdiameter(root->left);
214 pair<int,int> rightans=heightdiameter(root->right);
215
216 int leftheight=leftans.first;
217 int leftdiameter=leftans.second;
218 int rightheight=rightans.first;
219 int rightdiameter=rightans.second;
220
221 int height=1 + max(leftheight,rightheight);
222 int diameter = max(leftheight+rightheight,max(leftdiameter,rightdiameter));
223
224 pair<int,int>p;
225 p.first=height;
226 p.second=diameter;
227 return p;
228}
229
230int sumofallnodes(binarytree<int>*root)
231{

Callers

nothing calls this directly

Calls 1

maxFunction · 0.50

Tested by

no test coverage detected