APCS/12 Graphs/03-05 AdjList/AdjList.java
Rushil Umaretiya 3fc3554899 initial commit
2020-12-04 22:00:49 -05:00

100 lines
2.2 KiB
Java

// Name:
// Date:
import java.util.*;
import java.io.*;
/* Resource classes and interfaces
* for use with Graphs3: EdgeList,
* Graphs4: DFS-BFS
* and Graphs5: EdgeListCities
*/
/* Graphs 3: EdgeList
*/
interface VertexInterface
{
String toString(); // Don't use commas in the list. Example: "C [C D]"
String getName();
ArrayList<Vertex> getAdjacencies();
void addEdge(Vertex v);
}
class Vertex implements VertexInterface
{
private final String name;
private ArrayList<Vertex> adjacencies;
/* enter your code here */
}
interface AdjListInterface
{
List<Vertex> getVertices();
Vertex getVertex(int i) ;
Vertex getVertex(String vertexName);
Map<String, Integer> getVertexMap();
void addVertex(String v);
void addEdge(String source, String target);
String toString(); //returns all vertices with their edges (omit commas)
}
/* Graphs 4: DFS and BFS
*/
interface DFS_BFS
{
List<Vertex> depthFirstSearch(String name);
List<Vertex> depthFirstSearch(Vertex v);
List<Vertex> breadthFirstSearch(String name);
List<Vertex> breadthFirstSearch(Vertex v);
/* three extra credit methods */
List<Vertex> depthFirstRecur(String name);
List<Vertex> depthFirstRecur(Vertex v);
void depthFirstRecurHelper(Vertex v, ArrayList<Vertex> reachable);
}
/* Graphs 5: Edgelist with Cities
*/
interface EdgeListWithCities
{
void graphFromEdgeListData(String fileName) throws FileNotFoundException;
int edgeCount();
int vertexCount(); //count the vertices in the object
boolean isReachable(String source, String target);
boolean isConnected();
}
public class AdjList implements AdjListInterface //,DFS_BFS //,EdgeListWithCities
{
private ArrayList<Vertex> vertices = new ArrayList<Vertex>();
private Map<String, Integer> nameToIndex = new TreeMap<String, Integer>();
/* enter your code here */
/* three extra credit methods, recursive version */
List<Vertex> depthFirstRecur(String name)
{
return null;
}
List<Vertex> depthFirstRecur(Vertex v)
{
return null;
}
void depthFirstRecurHelper(Vertex v, ArrayList<Vertex> reachable)
{
}
}