Write a program to find depth of binary search tree without using recursion
Anonimo
In C++ using stack and pair classes: int maxDepth(Node* n) { stack> st; st.push(make_pair(n, 0)); int max = 0; while(!st.empty()) { pair cur = st.top(); st.pop(); if(cur.first->left) st.push(make_pair(cur.first->left,cur.second+1)); if(cur.first->right) st.push(make_pair(cur.first->right,cur.second+1)); if(max < cur.second) max = cur.second; } return max; }