Commit 59292373 authored by trh010's avatar trh010
Browse files

Vertex now extends HeapElt

parent d55ac7c2
...@@ -21,7 +21,7 @@ public class AdjacencyList { ...@@ -21,7 +21,7 @@ public class AdjacencyList {
ArrayList<Edge> neighbors = new ArrayList<Edge>(); ArrayList<Edge> neighbors = new ArrayList<Edge>();
for (int i = 0; i < adjList.size(); i++) { for (int i = 0; i < adjList.size(); i++) {
Vertex testVertex = adjList.get(i); Vertex testVertex = adjList.get(i);
int numDifferences = numDifferences(testVertex.getKey(), newWord); int numDifferences = numDifferences((String)testVertex.getRecord(), newWord);
if (2 >= numDifferences) { if (2 >= numDifferences) {
int weight = 0; int weight = 0;
if(numDifferences == 1) if(numDifferences == 1)
...@@ -55,7 +55,7 @@ public class AdjacencyList { ...@@ -55,7 +55,7 @@ public class AdjacencyList {
StringBuffer out = new StringBuffer(); StringBuffer out = new StringBuffer();
for (int i = 0; i < v.getEdges().size(); i++) { for (int i = 0; i < v.getEdges().size(); i++) {
int neighborHandle = v.getEdges().get(i).toVertex; int neighborHandle = v.getEdges().get(i).toVertex;
String neighborKey = adjList.get(neighborHandle).getKey(); String neighborKey = (String)adjList.get(neighborHandle).getRecord();
out.append(neighborKey + " (" + v.getEdges().get(i).weight + "), "); out.append(neighborKey + " (" + v.getEdges().get(i).weight + "), ");
} }
return out.toString(); return out.toString();
...@@ -65,7 +65,7 @@ public class AdjacencyList { ...@@ -65,7 +65,7 @@ public class AdjacencyList {
StringBuffer out = new StringBuffer(); StringBuffer out = new StringBuffer();
for (int i = 0; i < v.getEdges().size(); i++) { for (int i = 0; i < v.getEdges().size(); i++) {
int neighborHandle = v.getEdges().get(i).toVertex; int neighborHandle = v.getEdges().get(i).toVertex;
String neighborKey = adjList.get(neighborHandle).getKey(); String neighborKey = (String)adjList.get(neighborHandle).getRecord();
out.append(" " + neighborKey + " (" out.append(" " + neighborKey + " ("
+ v.getEdges().get(i).weight + ") "); + v.getEdges().get(i).weight + ") ");
if (i % 6 == 5) if (i % 6 == 5)
...@@ -80,7 +80,7 @@ public class AdjacencyList { ...@@ -80,7 +80,7 @@ public class AdjacencyList {
public int findStringHandle(String s) { public int findStringHandle(String s) {
for (int i = 0; i < adjList.size(); i++) { for (int i = 0; i < adjList.size(); i++) {
if (s.equals(adjList.get(i).getKey())) if (s.equals(adjList.get(i).getRecord()))
return i; return i;
} }
return -1; return -1;
...@@ -92,7 +92,7 @@ public class AdjacencyList { ...@@ -92,7 +92,7 @@ public class AdjacencyList {
out.append("------------------|------------\n"); out.append("------------------|------------\n");
for (int i = 0; i < adjList.size(); i++) { for (int i = 0; i < adjList.size(); i++) {
out.append(String out.append(String
.format("%5d %5s", i, adjList.get(i).getKey()) .format("%5d %5s", i, adjList.get(i).getRecord())
+ " | " + neighborsToString(adjList.get(i)) + "\n"); + " | " + neighborsToString(adjList.get(i)) + "\n");
} }
return out.toString(); return out.toString();
...@@ -108,8 +108,6 @@ public class AdjacencyList { ...@@ -108,8 +108,6 @@ public class AdjacencyList {
} }
getVertexFromHandle(startingVertex).setDist(0); getVertexFromHandle(startingVertex).setDist(0);
} }
private ArrayList<Integer> findPath(int start, int end, ArrayList<Integer> path){ private ArrayList<Integer> findPath(int start, int end, ArrayList<Integer> path){
......
package main; package main;
import heap.HeapElt;
import java.util.ArrayList; import java.util.ArrayList;
public class Vertex { public class Vertex extends HeapElt{
private String key;
private int handle;
private ArrayList<Edge> edges; private ArrayList<Edge> edges;
private int pred; private int pred;
private int dist; private int dist;
public Vertex(String word, int handle, ArrayList<Edge> neighbors) { public Vertex(String word, int handle, ArrayList<Edge> neighbors) {
this.key = word; this.record = word;
this.handle = handle; this.handle = handle;
this.edges = neighbors; this.edges = neighbors;
pred = -1; pred = -1;
...@@ -42,10 +41,6 @@ public class Vertex { ...@@ -42,10 +41,6 @@ public class Vertex {
this.handle = handle; this.handle = handle;
} }
public String getKey() {
return key;
}
public void addEdge(int n, int weight) { public void addEdge(int n, int weight) {
edges.add(new Edge(n, weight)); edges.add(new Edge(n, weight));
} }
......
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