-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
49 lines (42 loc) · 980 Bytes
/
test.php
File metadata and controls
49 lines (42 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* Created by PhpStorm.
* User: gussa
* Date: 5/20/16
* Time: 10:56 AM
*/
require "Graph.php";
//Creation of a graph analysis program
$graph = array(
'A' => array('B', 'F'),
'B' => array('A', 'D', 'E'),
'C' => array('F'),
'D' => array('B', 'E'),
'E' => array('B', 'D', 'F'),
'F' => array('A', 'E', 'C'),
);
$inputPath = array();
echo "Name 5 paths you want to discover!" . PHP_EOL;
for($i = 0; $i < 10; $i++) {
$inputPath[$i] = fgetc(STDIN);
$dummy = fgetc(STDIN);
}
// inputPath[0] = 'SOURCE' -> inputPath[1] = 'DESTINATION'
$g = new Graph($graph);
$i = 0;
while($i < 10){
$pid = pcntl_fork();
if($pid == -1) {
die('could not fork');
} else if ($pid) {
pcntl_wait($status);
} else {
$ppid = posix_getpid();
$j = $i + 1;
echo "I am child {$ppid} ran" ,
$g->breadthFirstSearch($inputPath[$i],$inputPath[$j]) . PHP_EOL;
exit;
}
$i = $i + 2;
}
?>