-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bellamanford.java
106 lines (98 loc) · 1.66 KB
/
Bellamanford.java
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import java.util.ArrayList;
// one class needs to have a main() method
public class HelloWorld
{
// arguments are passed using the text field below this editor
public static void main(String[] args)
{
Graph myGraph = new Graph(5, 5);
// System.out.print(myGraph);
}
}
public class Edge
{
private int source, destination, distance;
public Edge()
{
source =0;
destination=0;
distance=0;
}
public void SetSource(int src)
{
source = src;
}
public int GetSource()
{
return source;
}
public void SetDestination(int dest)
{
destination = dest;
}
public int GetDestination()
{
return destination;
}
public void SetDistance(int dist)
{
distance = dist;
}
public int GetDistance()
{
return distance;
}
}
public class Graph
{
private ArrayList<Edge> edges;
private int V;
private int E;
public Graph(int nOfV, int nOfE)
{
V = nOfV;
E = nOfE;
edges = new ArrayList<Edge>(nOfE);
}
public int GetNumberOfVertices()
{
return V;
}
public ArrayList<Edge> GetEdges()
{
return edges;
}
public void SetEdge(int index, Edge newEdge)
{
edges.set(index, newEdge);
}
}
public class Bellmanford
{
private Graph myGraph;
private int[] distances;
private Initialize(int nOfV)
{
for(int i = 0; i<nOfV; i++)
{
distances[i] = 0;
}
}
public Bellmanford()
{
// Read input from commandline and construct Graph
}
public void Run()
{
// Algorithm goes here
}
public void Display()
{
// Display results from here
}
public boolean DetectNegativeLoops()
{
boolean retValue = false;
return retValue;
}
}