import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Set; import java.util.Stack; /** * @author your name(s) here. * Extra Credit Options Implemented, if any: (mention them here.) * * Solution to Assignment 5 in CSE 373, Autumn 2014 * University of Washington. * * Starter code provided by Steve Tanimoto, Nov. 17, 2014, * version for Java 7 (also works with Java 8) Nov. 19, 2014. * */ // Here is the main application class: public class ExploredGraphJ7 { Set Ve; // collection of explored vertices Set Ee; // collection of explored edges public ExploredGraphJ7() { Ve = new LinkedHashSet(); Ee = new LinkedHashSet(); } public void initialize() { // Implement this } public int nvertices() {return 0;} // Implement this. public int nedges() {return 0;} // Implement this. public void dfs(Vertex vi, Vertex vj) {} // Implement this. public void bfs(Vertex vi, Vertex vj) {} // Implement this. public ArrayList retrievePath(Vertex vi) {return null;} // Implement this. public ArrayList shortestPath(Vertex vi, Vertex vj) {return null;} // Implement this. public Set getVertices() {return Ve;} public Set getEdges() {return Ee;} /** * @param args */ public static void main(String[] args) { ExploredGraphJ7 eg = new ExploredGraphJ7(); // Test the vertex constructor: Vertex v0 = eg.new Vertex("[[4,3,2,1],[],[]]"); System.out.println(v0); // Add your own tests here. // The autograder code will be used to test your basic functionality later. } class Vertex { Stack[] pegs; // Each vertex will hold a Towers-of-Hanoi state. // There will be 3 pegs in the standard version, but more if you do extra credit option A5E1. // Constructor that takes a string such as "[[4,3,2,1],[],[]]": public Vertex(String vString) { String[] parts = vString.split("\\],\\["); pegs = new Stack[3]; for (int i=0; i<3;i++) { pegs[i] = new Stack(); try { parts[i]=parts[i].replaceAll("\\[",""); parts[i]=parts[i].replaceAll("\\]",""); ArrayList al = new ArrayList(Arrays.asList(parts[i].split(","))); System.out.println("ArrayList al is: "+al); Iterator it = al.iterator(); while (it.hasNext()) { Object item = it.next(); System.out.println("item is: "+item); Integer diskInteger = new Integer((String)item); pegs[i].push(diskInteger); } } catch(Exception e) {} } } public String toString() { String ans = "["; for (int i=0; i<3; i++) { ans += pegs[i].toString().replace(" ",""); if (i<2) { ans += ","; } } ans += "]"; return ans; } } class Edge { public Edge(Vertex vi, Vertex vj) { // Add whatever you need to here. } } class Operator { public Operator(){} // Implement this. Adjust the signature as needed. // Additional explanation of what to do here will be given in GoPost or as extra text in the spec. boolean testPrecondition(Vertex v) {return false;} // implement this. Vertex applyTransition(Vertex v) {return null;} // implement this. public String toString() {return null;} // implement this. } }