#include <iostream>

using namespace std;

struct TNode {
  int m_nVal;
  TNode *m_pLeft;
  TNode *m_pRight;
};

void tree_depth(TNode*, int&);

bool is_balanced(TNode *pRoot) {
  if(pRoot==NULL)
    return true;

  int dLeft = 0, dRight = 0;
  tree_depth(pRoot->m_pLeft, dLeft);
  tree_depth(pRoot->m_pRight, dRight);

  int diff = dLeft-dRight;
  if(diff<=1 && diff>=-1)
    return true;
  else
    return false;
}

void tree_depth(TNode *pTree, int &depth) {
  if(pTree==NULL)
    return;

  int dLeft = 0, dRight = 0;
  tree_depth(pTree->m_pLeft, dLeft);
  tree_depth(pTree->m_pRight, dRight);

  if(dLeft>dRight)
    depth = dLeft+1;
  else
    depth = dRight+1;
}


int main(int argc, char **argv) {

  return 0;
}
