Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- public class Main
- {
- public static void main(String[] args)
- {
- UndirectedAdjacencyMatrixGraph<VertexDate, EdgeDate> graph = new UndirectedAdjacencyMatrixGraph<>(100);
- }
- }
- class UndirectedAdjacencyMatrixGraph<V, E> extends Graph<V, E>
- {
- ArrayList<ArrayList<Graph<V, E>.Edge<E>>> adjacencyMatrix;
- public UndirectedAdjacencyMatrixGraph(int initialCapacityOfAdjacencyMatrix)
- {
- this.adjacencyMatrix = new ArrayList<>(initialCapacityOfAdjacencyMatrix);
- for (int i = 0; i < initialCapacityOfAdjacencyMatrix; i++)
- adjacencyMatrix.add(new ArrayList<>(initialCapacityOfAdjacencyMatrix));
- }
- @Override
- public Graph<V, E>.Vertex<V> insertVertex(V v)
- {
- return null;
- }
- @Override
- public Graph<V, E>.Edge<E> insertEdge(Graph<V, E>.Vertex<V> from, Graph<V, E>.Vertex<V> to, E w)
- {
- return null;
- }
- @Override
- public void removeVertex(Graph<V, E>.Vertex<V> v)
- {
- }
- @Override
- public void removeEdge(Graph<V, E>.Edge<E> e)
- {
- }
- @Override
- public boolean areAdjacent(Graph<V, E>.Vertex<V> v, Graph<V, E>.Vertex<V> u)
- {
- return false;
- }
- @Override
- public boolean areAdjacent(Graph<V, E>.Edge<E> v, Graph<V, E>.Edge<E> u)
- {
- return false;
- }
- @Override
- public int degree(Graph<V, E>.Vertex<V> v)
- {
- return 0;
- }
- }
- class VertexDate
- {
- public String name;
- public Double penalty;
- }
- class EdgeDate
- {
- public Double cost;
- }
- abstract class Graph<V, E>
- {
- protected List<Vertex<V>> vertices;
- protected List<Edge<E>> edges;
- abstract public Vertex<V> insertVertex(V v);
- abstract public Edge<E> insertEdge(Vertex<V> from, Vertex<V> to, E w);
- abstract public void removeVertex(Vertex<V> v);
- abstract public void removeEdge(Edge<E> e);
- abstract public boolean areAdjacent(Vertex<V> v, Vertex<V> u);
- abstract public boolean areAdjacent(Edge<E> v, Edge<E> u);
- abstract public int degree(Vertex<V> v);
- abstract class Vertex<V>
- {
- protected V data;
- protected int positionInList;
- public Vertex(V data, int positionInList)
- {
- this.data = data;
- this.positionInList = positionInList;
- }
- public V getData()
- {
- return data;
- }
- public int getPositionInList()
- {
- return positionInList;
- }
- }
- abstract class Edge<E>
- {
- protected Vertex<V> endPoint1;
- protected Vertex<V> endPoint2;
- protected E data;
- protected int positionInList;
- public Edge(Vertex<V> endPoint1, Vertex<V> endPoint2, E data, int positionInList)
- {
- this.endPoint1 = endPoint1;
- this.endPoint2 = endPoint2;
- this.data = data;
- this.positionInList = positionInList;
- }
- public Vertex<V> getEndPoint1()
- {
- return endPoint1;
- }
- public Vertex<V> getEndPoint2()
- {
- return endPoint2;
- }
- public E getData()
- {
- return data;
- }
- public int getPositionInList()
- {
- return positionInList;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement