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

Function diameter

CPP/Trees/Diameter_of_tree.cpp:30–37  ·  view source on GitHub ↗

Computes the diameter of binary tree with given root. */

Source from the content-addressed store, hash-verified

28
29/* Computes the diameter of binary tree with given root. */
30int diameter(Node *root)
31{
32 if (root == NULL)
33 return 0;
34 int ans = INT_MIN; // This will store the final answer
35 height(root, ans);
36 return ans;
37}
38
39struct Node *newNode(int data)
40{

Callers 1

mainFunction · 0.85

Calls 1

heightFunction · 0.70

Tested by

no test coverage detected