Creating a program to find longest path

Posted by stef89 on Stack Overflow See other posts from Stack Overflow or by stef89
Published on 2010-05-08T20:44:57Z Indexed on 2010/05/08 20:48 UTC
Read the original article Hit count: 244

Filed under:
|

Hi everyone,

I'm fairly new to programming and I'm having a few problems. Basically I have to make a function that will find the lengths of all the paths through a network diagram. I've been working on this for hours but I can't seem to get anywhere. Using recursion I can navigate through every path but I'm just unsure as to how I should record the lengths of the paths.

Any help would be greatly appreciated. Thanks!

$dependencies = array("","","","1","3","4,2");
$durations = array("5","3","4","11","9","10");


function tracePath($path,$dependencies,$durations,$returnArray=array()) {

    if($dependencies[$path] != "") {
        $currentTaskDependencies = preg_split("/[\s]*[,][\s]*/", $dependencies[$path]);

       for($i=0;$i<count($currentTaskDependencies);$i++) {
          tracePath($currentTaskDependencies[$i]-1,$dependencies,$durations,$returnArray[$i]);
       }    
    }
    return $returnArray;
 }

tracePath(6,$dependencies,$durations);

© Stack Overflow or respective owner

Related posts about php

Related posts about recursion