Esempio n. 1
0
int BST::findDepth(Node* node)
{
  if (!(node->left) && !(node->right))
    return 0;
 
  int leftDepth = 0;
  if (node->left)
    leftDepth = findDepth(node->left);

  int rightDepth = 0;
  if (node->right)
    rightDepth = findDepth(node->right);

  return ((leftDepth > rightDepth) ? leftDepth : rightDepth) + 1;
}
Esempio n. 2
0
static int findDepth(classNode* c, int count, int max) {
    assert(count <= max);
    count++;
    if (c->prereqs.size() == 0) {
        return 0;
    }
    int maxDepth = 0;
    for (auto c2 : c->prereqs) {
        int newDepth = findDepth(c2, count, max);
        if (newDepth > maxDepth) {
            maxDepth = newDepth;
        }
    }
    return maxDepth + 1;
}
Esempio n. 3
0
void Classes::fixDepths() {
    for (auto c : classes) {
        int count = 0;
        c->depth = findDepth(c, count, classes.size());
    }
}