Commit e0afcb6c authored by trh010's avatar trh010
Browse files

changed things around and began the adjList toString function

parent 6da347cf
......@@ -4,14 +4,28 @@ import java.util.ArrayList;
public class AdjacencyList {
private ArrayList<ArrayList<Vertex>> adjList;
private ArrayList<Vertex> adjList;
public AdjacencyList() {
adjList = new ArrayList<ArrayList<Vertex>>();
adjList = new ArrayList<Vertex>();
}
public void addNode(String newWord) {
}
public ArrayList<Integer> getNeighbors(Integer vertexHandle) {
return adjList.get(vertexHandle).getNeighbors();
}
public String toString() {
String out = "";
out += "Handle Key | Neighbors \n";
out += "------------------|------------\n";
for (int i = 0; i < adjList.size(); i++) {
out += String.format("%5d %5s", i, adjList.get(i).getKey())
+ " |\n";
}
return out;
}
}
......@@ -29,6 +29,7 @@ public class Main {
adjList.addNode(in.next());
}
in.close();
System.out.println(adjList.toString());
} catch (FileNotFoundException e) {
System.err.println("Error in opening the file: " + path
+ ". Please check the file path.");
......
package main;
import java.util.ArrayList;
public class Vertex {
private String word;
private String key;
private int handle;
private ArrayList<Integer> neighbors;
public Vertex(String word, int handle) {
this.word = word;
public Vertex(String word, int handle, ArrayList<Integer> neighbors) {
this.key = word;
this.handle = handle;
this.neighbors = new ArrayList<Integer>();
}
public int getHandle() {
......@@ -18,8 +22,15 @@ public class Vertex {
this.handle = handle;
}
public String getWord() {
return word;
public String getKey() {
return key;
}
public void addNeighbor(Integer n) {
neighbors.add(n);
}
public ArrayList<Integer> getNeighbors() {
return neighbors;
}
}
Supports Markdown
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