Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Greedy Algorithm - Java

807588May 2 2009 — edited May 2 2009
Hi

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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 30 2009
Added on May 2 2009
5 comments
1,113 views