Commit 12eb295b authored by trh010's avatar trh010
Browse files

Added better formatted output

parent ec071867
......@@ -56,6 +56,19 @@ public class AdjacencyList {
return out.toString();
}
public String neighborsToString2(Vertex v) {
StringBuffer out = new StringBuffer();
for (int i = 0; i < v.getEdges().size(); i++) {
int neighborHandle = v.getEdges().get(i).toVertex;
String neighborKey = adjList.get(neighborHandle).getKey();
out.append(" " + neighborKey + " ("
+ v.getEdges().get(i).weight + ") ");
if (i % 6 == 5)
out.append("\n");
}
return out.toString();
}
public Vertex getVertexFromHandle(int handle) {
return adjList.get(handle);
}
......@@ -65,7 +78,6 @@ public class AdjacencyList {
if (s.equals(adjList.get(i).getKey()))
return i;
}
return -1;
}
......
......@@ -29,13 +29,18 @@ public class Main {
adjList.addNode(in.next());
}
in.close();
System.out.println(adjList.toString());
// System.out.println(adjList.toString());
} catch (FileNotFoundException e) {
System.err.println("Error in opening the file: " + path
+ ". Please check the file path.");
}
}
/**
* Queries the user for a Word, then lists the word's neighbors. Continues
* this cycle if desired. Provides the functionality necessary for Part I of
* the assignment.
*/
public void queryUser() {
boolean queryingUser = true;
Scanner in = new Scanner(System.in);
......@@ -47,8 +52,11 @@ public class Main {
System.out.println("Input string " + s
+ " is not in the dictionary");
else
System.out.println(adjList.neighborsToString(adjList
.getVertexFromHandle(handle)));
System.out.println("The neighbors of "
+ s
+ " are:\n"
+ adjList.neighborsToString2(adjList
.getVertexFromHandle(handle)));
boolean validResponse = false;
while (!validResponse) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment