Java Reference
In-Depth Information
1 /**
2 * Process a request; return false if end of file.
3 */
4 public static boolean processRequest( Scanner in, Graph g )
5 {
6 try
7 {
8 System.out.print( "Enter start node:" );
9 String startName = in.nextLine( );
10
11 System.out.print( "Enter destination node:" );
12 String destName = in.nextLine( );
13
14 System.out.print( "Enter algorithm (u, d, n, a ): " );
15 String alg = in.nextLine( );
16
17 if( alg.equals( "u" ) )
18 g.unweighted( startName );
19 else if( alg.equals( "d" ) )
20 g.dijkstra( startName );
21 else if( alg.equals( "n" ) )
22 g.negative( startName );
23 else if( alg.equals( "a" ) )
24 g.acyclic( startName );
25
26 g.printPath( destName );
27 }
28 catch( NoSuchElementException e )
29 { return false; }
30 catch( GraphException e )
31 { System.err.println( e ); }
32 return true;
33 }
figure 14.15
For testing purposes,
processRequest calls
one of the shortest-
path algorithms
figure 14.16
The graph after the
starting vertex has
been marked as
reachable in zero
edges
V 0
V 1
0
V 2
V 3
V 4
V 5
V 6
 
Search WWH ::




Custom Search