From 79e04705c6eeed95992e5753a8328aad90e02f68 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sun, 20 Apr 2025 19:39:42 +0200 Subject: move each auxiliary class to own file, to please javadoc --- com/example/portfolio3/EdgeGraph.java | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 com/example/portfolio3/EdgeGraph.java (limited to 'com/example/portfolio3/EdgeGraph.java') diff --git a/com/example/portfolio3/EdgeGraph.java b/com/example/portfolio3/EdgeGraph.java new file mode 100644 index 0000000..ae9cbe9 --- /dev/null +++ b/com/example/portfolio3/EdgeGraph.java @@ -0,0 +1,37 @@ +package com.example.portfolio3; + +// origin: + +/// EdgeGraph - One big set of all edges in the graph +class EdgeGraph extends AbstractGraph { + + /// foo + EdgeGraph() {} + + /// foo + Set edges=new HashSet<>(); + + /// foo + public void insertEdge(Vertex v1,Vertex v2,int w){ + edges.add(new Edge(v1,v2,w)); + } + + /// foo + public Collection edges(){return edges;} + + /// foo + public Collection outEdge(Vertex v){ + ArrayList outEdge=new ArrayList<>(); + for(Edge e:edges)if(e.from()==v)outEdge.add(e); + return outEdge; + } + + /// foo + public Integer getWeight(Vertex v1,Vertex v2){ + // linear in number of edges in the graph + for(Edge e:edges){ + if(e.from()==v1 && e.to()==v2)return e.weight(); + } + return null; + } +} -- cgit v1.2.3