{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Check10D - i =(i< path.length 1 i 1 i vertex =...

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; while (i < path.length() && !crash && !end) { 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 Document Right 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 < path.length() - 1) ? i + 1 : i; vertex = path.substring(i, i + 1); edge += vertex; Map<String, Double> map = new TreeMap<String, Double>(); 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("Invalid path (Edge " + edge + " does not exist)"); } } else { end = !end; } } else { crash = !crash; out.println("Invalid path (Edge " + edge + " does not exist)"); } edge = ""; } out.printf("%s%n", (!crash && end) ? "The cost of this path is: " + cost : ""); } } //D:\Users\DJ\Downloads\York\Fall 2010\Programming\1020\Projects\CSE1020\src\lab10Bdata.dat...
View Full Document

{[ snackBarMessage ]}