Advertisement
habur331

Untitled

Apr 17th, 2022
852
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.39 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3.  
  4. public class Main
  5. {
  6.  
  7.     public static void main(String[] args)
  8.     {
  9.         UndirectedAdjacencyMatrixGraph<VertexDate, EdgeDate> graph = new UndirectedAdjacencyMatrixGraph<>(100);
  10.     }
  11. }
  12.  
  13. class UndirectedAdjacencyMatrixGraph<V, E> extends Graph<V, E>
  14. {
  15.  
  16.     ArrayList<ArrayList<Graph<V, E>.Edge<E>>> adjacencyMatrix;
  17.  
  18.     public UndirectedAdjacencyMatrixGraph(int initialCapacityOfAdjacencyMatrix)
  19.     {
  20.         this.adjacencyMatrix = new ArrayList<>(initialCapacityOfAdjacencyMatrix);
  21.         for (int i = 0; i < initialCapacityOfAdjacencyMatrix; i++)
  22.             adjacencyMatrix.add(new ArrayList<>(initialCapacityOfAdjacencyMatrix));
  23.     }
  24.  
  25.     @Override
  26.     public Graph<V, E>.Vertex<V> insertVertex(V v)
  27.     {
  28.         return null;
  29.     }
  30.  
  31.     @Override
  32.     public Graph<V, E>.Edge<E> insertEdge(Graph<V, E>.Vertex<V> from, Graph<V, E>.Vertex<V> to, E w)
  33.     {
  34.         return null;
  35.     }
  36.  
  37.     @Override
  38.     public void removeVertex(Graph<V, E>.Vertex<V> v)
  39.     {
  40.  
  41.     }
  42.  
  43.     @Override
  44.     public void removeEdge(Graph<V, E>.Edge<E> e)
  45.     {
  46.  
  47.     }
  48.  
  49.     @Override
  50.     public boolean areAdjacent(Graph<V, E>.Vertex<V> v, Graph<V, E>.Vertex<V> u)
  51.     {
  52.         return false;
  53.     }
  54.  
  55.     @Override
  56.     public boolean areAdjacent(Graph<V, E>.Edge<E> v, Graph<V, E>.Edge<E> u)
  57.     {
  58.         return false;
  59.     }
  60.  
  61.     @Override
  62.     public int degree(Graph<V, E>.Vertex<V> v)
  63.     {
  64.         return 0;
  65.     }
  66. }
  67.  
  68. class VertexDate
  69. {
  70.     public String name;
  71.     public Double penalty;
  72. }
  73.  
  74. class EdgeDate
  75. {
  76.     public Double cost;
  77. }
  78.  
  79. abstract class Graph<V, E>
  80. {
  81.     protected List<Vertex<V>> vertices;
  82.     protected List<Edge<E>> edges;
  83.  
  84.     abstract public Vertex<V> insertVertex(V v);
  85.  
  86.     abstract public Edge<E> insertEdge(Vertex<V> from, Vertex<V> to, E w);
  87.  
  88.     abstract public void removeVertex(Vertex<V> v);
  89.  
  90.     abstract public void removeEdge(Edge<E> e);
  91.  
  92.     abstract public boolean areAdjacent(Vertex<V> v, Vertex<V> u);
  93.  
  94.     abstract public boolean areAdjacent(Edge<E> v, Edge<E> u);
  95.  
  96.     abstract public int degree(Vertex<V> v);
  97.  
  98.     abstract class Vertex<V>
  99.     {
  100.         protected V data;
  101.         protected int positionInList;
  102.  
  103.         public Vertex(V data, int positionInList)
  104.         {
  105.             this.data = data;
  106.             this.positionInList = positionInList;
  107.         }
  108.  
  109.         public V getData()
  110.         {
  111.             return data;
  112.         }
  113.  
  114.         public int getPositionInList()
  115.         {
  116.             return positionInList;
  117.         }
  118.     }
  119.  
  120.     abstract class Edge<E>
  121.     {
  122.         protected Vertex<V> endPoint1;
  123.         protected Vertex<V> endPoint2;
  124.         protected E data;
  125.         protected int positionInList;
  126.  
  127.         public Edge(Vertex<V> endPoint1, Vertex<V> endPoint2, E data, int positionInList)
  128.         {
  129.             this.endPoint1 = endPoint1;
  130.             this.endPoint2 = endPoint2;
  131.             this.data = data;
  132.             this.positionInList = positionInList;
  133.         }
  134.  
  135.         public Vertex<V> getEndPoint1()
  136.         {
  137.             return endPoint1;
  138.         }
  139.  
  140.         public Vertex<V> getEndPoint2()
  141.         {
  142.             return endPoint2;
  143.         }
  144.  
  145.         public E getData()
  146.         {
  147.             return data;
  148.         }
  149.  
  150.         public int getPositionInList()
  151.         {
  152.             return positionInList;
  153.         }
  154.     }
  155. }
  156.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement