Repository navigation
Expand file tree
/
Copy pathNetworkUndirected.java
More file actions
executable file
·54 lines (44 loc) · 1.59 KB
/
Copy pathNetworkUndirected.java
File metadata and controls
executable file
·54 lines (44 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.example.graph;
import com.example.exceptions.*;
import com.example.interfaces.NetworkADT;
public class NetworkUndirected<T> extends NetworkDirected<T> implements NetworkADT<T> {
public NetworkUndirected(int capacity) {
super(capacity);
}
public NetworkUndirected() {
super();
}
/**
* {@inheritDoc }
*/
@Override
public void removeEdge(T vertex1, T vertex2) throws EmptyCollectionException, ElementNotFoundException, VertexConnectionExeception {
super.removeEdge(vertex1, vertex2);
this.vertices[getIndex(vertex2)].neighbors.remove(new GraphEdge(getIndex(vertex1), DEFAULT_WEIGHT));
}
/**
* {@inheritDoc }
*/
@Override
public void removeVertex(T vertex) throws EmptyCollectionException, ElementNotFoundException {
int tempEdges = this.numberOfEdges;
super.removeVertex(vertex);
this.numberOfEdges += (tempEdges - this.numberOfEdges) / 2;
}
/**
* {@inheritDoc }
*/
@Override
public void addEdge(T vertex1, T vertex2, double weight) throws ElementNotFoundException, VertexConnectionExeception {
super.addEdge(vertex1, vertex2, weight);
this.vertices[getIndex(vertex2)].neighbors.add(new GraphEdge(getIndex(vertex1), weight));
}
/**
* {@inheritDoc }
*/
@Override
public void addEdge(T vertex1, T vertex2) throws ElementNotFoundException, VertexConnectionExeception {
super.addEdge(vertex1, vertex2);
this.vertices[getIndex(vertex2)].neighbors.add(new GraphEdge(getIndex(vertex1), DEFAULT_WEIGHT));
}
}