//arrayofflights is the array of the unique flights
//resultarray2d is a 2 dimension array to store all possible route from startcity to endcity
// ex: result[][],
// result[1] indicate the array of one possible route which may include result[1][0], result[1][1],result[1][2],result[1][3],
// means cusotmer need to take four flight to reach the endcity
Class mc{
private arrayofflights;
private startcity, endcity, starttime, endtime;
private resultarray2d;
public class mc();
public class mc(rs, sc, ec,st,et){
arrayofflights = rs;
startcity = sc;
endcity = ec;
starttime = st;
endtime = et;
}
public 2darray findallpossibleroute(){
resultarray2d = findroute(arrayofflights, startcity, endcity, starttime, endtime, resultarray2d, 0 );
resultarray2d = remove all the arrays in the resultarray2d which last elment is the not endcity
}
private 2darray findroute(rs, sc, ec, st, et, resultary, index){
find all the fligts satisfy the sc, st, et condition, and not appear in the resultary[index] before
if (only one outcome){
append the outcome flight at the end of the resultary[index]
if (the only outcome != ec)
resultary = findroute(rs, newsc, ec, newst, et, resultary, index);
else
return resultary;
}
else if(no outcome){
return resultary;
}
else if (outcome more one){
first,set the corresponding ary value of outcomes to true
copy the resultary[index] into a temparray
for each element of outcome{
newarry = temparray+element
insert the newarry to the newindex position of resultary
if (the element != ec)
resultary = findroute(rs, newsc, ec, newst, et, resultary, newindex);
else
return resultary;
}
}
}
public ~class mc();
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment