Greedy Algorithm - Java
807588May 2 2009 — edited May 2 2009Hi
I have a few questions about the greedy algorithm.
This is my code:
private Array[] result;
public void makeGreedyPath(Vertex v)
{
int smallestPath = 999999999;
Vertex temp = null;
for(int i=0; i<getNumbeOfNeighbours(); i++)
{
for(int y = 0; y<currentEdges; y++)
{
if(edges[y].equals(v.getName()+v.getNeighbour(i).getName()) || edges[y].equals(v.getNeighbour(i).getName() + v.getName())
{
if(edges[y].getWeight() < smallestPath)
{
smallestPath = edges[y].getWeight();
temp = edges[y];
}
}
}
}
Now I want to add this result(temp) to my array, how do I do that?
How do I test if the vertex is already in my array?
Thanks