Ejemplo n.º 1
0
function getConsumerPath($con)
{
    global $nodes;
    $nodes = checkNodesGlobalVariable($con);
    $consumer_path = [];
    addToLog("\n\n\n;--------------------------------\n;        ESTABLISHING TRANSACTION PATH\n;--------------------------------");
    for ($b = 0; $b < sizeof($nodes); $b++) {
        $list = [];
        $providers = getProviders($b);
        for ($p = 0; $p < sizeof($providers); $p++) {
            if ($providers[$p] != null) {
                $list = array_merge($list, array(BFS($b, $providers[$p])));
            } else {
                echo "<br />No providers found for {$b} <br /><br />";
            }
        }
        $consumer_path = array_merge($consumer_path, $list);
        addToLog("\n\n" . implode("\n", str_replace(',', ' -> ', $list)));
    }
    return $consumer_path;
}
        $current_node = array_shift($queue);
        if ($current_node->level > $current_level) {
            $current_level++;
            array_push($output, "\n");
        }
        array_push($output, $current_node->info . " ");
        if ($current_node->left != NULL) {
            $current_node->left->level = $current_level + 1;
            array_push($queue, $current_node->left);
        }
        if ($current_node->right != NULL) {
            $current_node->right->level = $current_level + 1;
            array_push($queue, $current_node->right);
        }
    }
    return join("", $output);
}
/*
           9                  9
         2   4         =>     2 4
       1  3 5  7              1 3 5 7
*/
$root = new Node(9);
$root->left = new Node(2);
$root->right = new Node(4);
$root->left->left = new Node(1);
$root->left->right = new Node(3);
$root->right->left = new Node(5);
$root->right->right = new Node(7);
echo BFS($root);