public function filterNodeDepth($nodes, $depth)
    {
        if(empty($nodes) || $depth === 0)
        {
            return array();
        }

        $newNodes = array();
        $stack = array();
        $level = 0;

        foreach($nodes as $node)
        {
            $parent = end($stack);
            while($parent && $node->getLeftValue() > $parent->getRightValue())
            {
                array_pop($stack);
                $parent = end($stack);
                $level--;
            }

            if($level < $depth)
            {
                $newNodes[] = $node;
            }

            if(($node->getRightValue() - $node->getLeftValue()) > 1)
            {
                array_push($stack, $node);
                $level++;
            }
        }

        return $newNodes;
    }
public function filterNodeDepth($nodes, $depth)
    {
        if(empty($nodes) || $depth === 0)
        {
            return array();
        }

        $newNodes = array();
        $stack = array();
        $level = 0;

        foreach($nodes as $node)
        {
            $parent = end($stack);
            while($parent && $node->getLeftValue() > $parent->getRightValue())
            {
                array_pop($stack);
                $parent = end($stack);
                $level--;
            }

            if($level < $depth)
            {
                $newNodes[] = $node;
            }

            if(($node->getRightValue() - $node->getLeftValue()) > 1)
            {
                array_push($stack, $node);
                $level++;
            }
        }

        return $newNodes;
    }
public function filterNodeDepth ( $ nodes , $ depth ) { if ( empty ( $ nodes ) || $ depth === 0 ) { return array ( ) ; } $ newNodes = array ( ) ; $ stack = array ( ) ; $ level = 0 ; foreach ( $ nodes as $ node ) { $ parent = end ( $ stack ) ; while ( $ parent && $ node -> getLeftValue ( ) > $ parent -> getRightValue ( ) ) { array_pop ( $ stack ) ; $ parent = end ( $ stack ) ; $ level -- ; } if ( $ level < $ depth ) { $ newNodes [ ] = $ node ; } if ( ( $ node -> getRightValue ( ) - $ node -> getLeftValue ( ) ) > 1 ) { array_push ( $ stack , $ node ) ; $ level ++ ; } } return $ newNodes ; }
Internal
Filters an array of nodes by depth

@param array array of Node instances
@param int $depth the depth to filter to

@return array array of Node instances
Internal Filters an array of nodes by depth