private function traverse(TreeNode $node)
    {
        if ($node->visited) {
            return 0;
        }
        $node->visited = true;

        foreach ($node->getAdjacents() as $adjacent) {
            $this->traverse($adjacent);
        }

        return 1;
    }
private function traverse(TreeNode $node)
    {
        if ($node->visited) {
            return 0;
        }
        $node->visited = true;

        foreach ($node->getAdjacents() as $adjacent) {
            $this->traverse($adjacent);
        }

        return 1;
    }
private function traverse ( TreeNode $ node ) { if ( $ node -> visited ) { return 0 ; } $ node -> visited = true ; foreach ( $ node -> getAdjacents ( ) as $ adjacent ) { $ this -> traverse ( $ adjacent ) ; } return 1 ; }
Traverse node, and return 1 if node has not been visited yet

@param TreeNode $node
@return int
Traverse node and return 1 if node has not been visited yet