Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > programming - mental masterbation...

programming - mental masterbation...
Thread Tools
chronus_maximus
Guest
Status:
Reply With Quote
Nov 19, 2000, 10:59 PM
 
Hi

I'm just learning java and one of the projects I'm working on is doing the Dijkstra Algorithm. My problem is not the Dijkstra algorithm -- it does work! My problem is how I have to input the data:

public class TestShortestPath
{
public static void main(String[] args)
{
dijkstra theGraph = new dijkstra();

theGraph.addVertex('O'); // 0 (start)
theGraph.addVertex('A'); // 1
theGraph.addVertex('B'); // 2
theGraph.addVertex('C'); // 3
theGraph.addVertex('D'); // 4
theGraph.addVertex('E'); // 5
theGraph.addVertex('T'); // 6

theGraph.addedge(0, 1, 2); // O to A is 2
theGraph.addedge(0, 2, 5); // O to B is 5
theGraph.addedge(0, 3, 4); // O to C is 4

theGraph.addedge(1, 4, 7); // A to D is 7
theGraph.addedge(1, 2, 2); // A to B is 2
theGraph.addedge(1, 0, 2); // A to O is 2

theGraph.addedge(2, 1, 2); // B to A is 2
theGraph.addedge(2, 0, 3); // B to O is 3
theGraph.addedge(2, 3, 1); // B to C is 1
theGraph.addedge(2, 5, 3); // B to E is 3
theGraph.addedge(2, 4, 4); // B to D is 4

theGraph.addedge(3, 5, 4); // C to E is 4
theGraph.addedge(3, 2, 1); // C to B is 1
theGraph.addedge(3, 0, 4); // C to O is 4

theGraph.addedge(4, 1, 7); // D to A is 7
theGraph.addedge(4, 2, 4); // D to B is 4
theGraph.addedge(4, 6, 5); // D to T is 5
theGraph.addedge(4, 5, 1); // D to E is 1

theGraph.addedge(5, 6, 7); // E to T is 7
theGraph.addedge(5, 4, 1); // E to D is 1
theGraph.addedge(5, 2, 3); // E to B is 3
theGraph.addedge(5, 3, 4); // E to C is 4

theGraph.addedge(6, 5, 7); // T to E is 7
theGraph.addedge(6, 4, 5); // T to D is 5


System.out.println("Shortest Paths from Node O : ");
theGraph.path();
System.out.println();
} //end main()
}//end class TestShortestPath
//-------------------------------------------

The above is dealt with this:

/*
* Procedure addVertex. Takes a characther as input and
* adds it to the metrix array.
*/
public void addVertex(char m)
{
vertexList[vertCount++] = new Vertex(m);
}

/*
* Procedure addedge. Double matrix with the starting
* and ending edges. Int x is the distance from each other.
*/
public void addedge(int start, int end, int x)
{
adjMatrix[start][end] = x;
}

What is what I need? A for-loop that will convert the above into an elegant for-loop procedure in Java. So the user can put whatever he or she wants.

I would greatly appreciate your help.
     
Clinically Insane
Join Date: Apr 2000
Status: Offline
Reply With Quote
Nov 20, 2000, 02:45 AM
 
When you post a topic, please limit it to ONE forum.
It can't be that hard to choose one...

Cipher13
     
Dedicated MacNNer
Join Date: Nov 1999
Location: Georgetown, Demerara, Guyana
Status: Offline
Reply With Quote
Nov 28, 2000, 03:54 AM
 
Hi chronus_maximus,

I'm no Java expert, but I'll try to offer some suggestions... For some general examples of using loops to read in user-input from the keyboard, see the earlier C Programmers NEEDED desperately!! Will pay MONEY!!! thread in this Forum. The examples involve C rather than Java, but it should be relatively easy to convert the concept (using 'DataInputStream.readline', or whetever, instead of 'scanf').

Regards,

--Paul
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:02 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2