Check10D - i = (i < path.length() - 1) ? i + 1 :...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.*; import java.io.*; i public class Check10D { @SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { PrintStream out = System.out; Scanner in = new Scanner(System.in); out.print("Filename of the graph . .. "); ObjectInputStream input = new ObjectInputStream(new FileInputStream(in.nextLine())); Object buffer = input.readObject(); Map<String, TreeMap<String, Double>> graph = new TreeMap<String, TreeMap<String, Double>>(); if (buffer instanceof Map) { graph = (Map<String, TreeMap<String, Double>>)buffer; } input.close(); out.print("Enter the path . .. "); String path = in.nextLine(), edge = "", vertex; int i = 0; double cost = 0; boolean crash = false, end = false; { vertex = path.substring(i, i + 1); edge += vertex;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: i = (i &lt; path.length() - 1) ? i + 1 : i; vertex = path.substring(i, i + 1); edge += vertex; Map&lt;String, Double&gt; map = new TreeMap&lt;String, Double&gt;(); if (graph.containsKey(edge.substring(0, 1))) { map = graph.get(edge.substring(0, 1)); if (edge.charAt(0) != edge.charAt(1)) { if (map.containsKey(edge.substring(1))) { cost += map.get(edge.substring(1)); } else { crash = !crash; out.println(&quot;Invalid path (Edge &quot; + edge + &quot; does not exist)&quot;); } } else { end = !end; } } else { crash = !crash; out.println(&quot;Invalid path (Edge &quot; + edge + &quot; does not exist)&quot;); } edge = &quot;&quot;; } out.printf(&quot;%s%n&quot;, (!crash &amp;&amp; end) ? &quot;The cost of this path is: &quot; + cost : &quot;&quot;); } } //D:\Users\DJ\Downloads\York\Fall 2010\Programming\1020\Projects\CSE1020\src\lab10Bdata.dat...
View Full Document

This note was uploaded on 09/16/2011 for the course CSE CSE 1020 taught by Professor Burton,ma during the Fall '10 term at York University.

Page1 / 2

Check10D - i = (i &amp;amp;lt; path.length() - 1) ? i + 1 :...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online