Commit 5ebfe2a4 authored by trh010's avatar trh010
Browse files

printing, adding vertex complete

parent edfb606e
......@@ -11,7 +11,7 @@ public class AdjacencyList {
}
public void addNode(String newWord) {
int newHandle = adjList.size() - 1;
int newHandle = adjList.size();
ArrayList<Integer> neighbors = findAndSetNeighbors(newWord, newHandle);
Vertex newVertex = new Vertex(newWord, newHandle, neighbors);
adjList.add(newVertex);
......@@ -31,11 +31,13 @@ public class AdjacencyList {
/**
* Tests if two strings should be neighbors to each other. Two string should
* be neighbors if
* be neighbors if they have less that or equal to 2 differences (in order).
*
* @param a
* the first string
* @param b
* @return
* the second string
* @return true if the strings are related, false if they are not
*/
public boolean areRelated(String a, String b) {
if (a.length() != b.length())
......@@ -67,13 +69,14 @@ public class AdjacencyList {
}
public String toString() {
String out = "";
out += "Handle Key | Neighbors \n";
out += "------------------|------------\n";
StringBuffer out = new StringBuffer();
out.append("Handle Key | Neighbors \n");
out.append("------------------|------------\n");
for (int i = 0; i < adjList.size(); i++) {
out += String.format("%5d %5s", i, adjList.get(i).getKey())
+ " |\n";
out.append(String
.format("%5d %5s", i, adjList.get(i).getKey())
+ " | " + neighborsToString(adjList.get(i)) + "\n");
}
return out;
return out.toString();
}
}
......@@ -11,7 +11,7 @@ public class Vertex {
public Vertex(String word, int handle, ArrayList<Integer> neighbors) {
this.key = word;
this.handle = handle;
this.neighbors = new ArrayList<Integer>();
this.neighbors = neighbors;
}
public int getHandle() {
......
BEAST BLAST BOAST BOATS
COAST COATS CODES COSTS
ROADS ROAST TOADS TOAST
BEAST BLAST BOAST BOATS
COAST COATS CODES COSTS
ROADS ROAST TOADS TOAST
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