need help in dijkstra algrothims

want use dijkstra al gorithm to finde shoterst distance between two Nodes .

If I'll go from node 1 to node 2 in matrix must go through node 3 , will be from 1 to 3 then 3 to 2 but i'm stuck

in this part i went trough breadth first search it;s difficult to use it in matrix it's ok for graph.

so if any one can help me in it please these some testing code.

thanks

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

//declaring class

public class testpro extends Applet implements ActionListener

{ //declaring the TextField

private TextField vField ,wField;

//declaring an array

int c[][];

int d[]; // distance

int m = 99; // Infinity value

//declaring values of text field

private int v ;

private int w;

public void init()

{

vField = new TextField(5);

add(vField);

// register listener using void add actionListener

vField.addActionListener(this);

wField = new TextField(5);

add(wField);

// register listener using void add actionListener

wField.addActionListener(this);

}

// event handler methods

public void actionPerformed(ActionEvent event) {

//declaring textfield

v=Integer.parseInt(vField.getText());

w=Integer.parseInt(wField.getText());

d = new int[7];

c =new int[7][7];

c[1][1] = 0; c[2][1]= 5; c[3][1]= 1;

c[1][2]= 5; c[2][2]= 0; c[3][2]= 2;

c[1][3]= 1; c[2][3]= 2; c[3][3]= 0;

c[1][4]= 99; c[2][4]= 3; c[3][4]= 8;

c[1][5]= 99; c[2][5]= 99; c[3][5]= 1;

c[1][6]= 99; c[2][6]= 99; c[3][6]= 99;

c[4][1] = 99; c[5][1]= 99; c[6][1]= 99;

c[4][2]= 3; c[5][2]= 99; c[6][2]= 99;

c[4][3]= 8; c[5][3]= 1; c[6][3]= 99;

c[4][4]= 0; c[5][4]= 1; c[6][4]= 1;

c[4][5]= 1; c[5][5]= 0; c[6][5]= 5;

c[4][6]= 1; c[5][6]= 5; c[6][6]= 0;

for (int v=1; v<7; ++v) {

for (int w=1; w<7; ++w) {

repaint();

}

}

}

public void paint(Graphics g) {

//initialis start node

if (v==1&&w==1){

d[w] = c[1][w];

d[w] = c[1][1]; // start Node is v = 1 end node is w = 1

g.drawString("Distance = "+d[w],300, 150 );

}

if(v==1 && w==2) {

d[w] = c[1][w]

m = d[w];

if (c[1][2]>c[1][3] + c[3][2]) {

d[w] = c[1][3]+c[3][2];

} else {d[w] = c[1][2];}

g.drawString("Distance = "+d[w],300, 150 );

}

}

}

[2537 byte] By [anny_warda] at [2007-9-29 23:51:41]
# 1
Did you read the other threads in this forum on dijkstra?
jschella at 2007-7-16 4:18:53 > top of Java-index,Other Topics,Algorithms...
# 2
Thanks for replay I checked most of them they are talking about graphs and I齧 new in java and I using java applet also I齧 not familiar rest type of java so that why it齭 difficult for me to do it. If any one help me in it I appreciate that.thanks
anny_warda at 2007-7-16 4:18:53 > top of Java-index,Other Topics,Algorithms...
# 3
Your matrix is a representation of a graph.
YATArchivista at 2007-7-16 4:18:53 > top of Java-index,Other Topics,Algorithms...
# 4

This is right codes to do algorithms through Matrix

2nd plm to print value of S

thanks again

// Desition = 2

if(w==2) {

d[w]=c[1][w]; // d[w] is the cost beween Node2

if ( d[w]>0 && d[w]<m);

v = 3;// shrtest distance from node 2 via node 3

d[v]=c[1][v];

S = v;// add 3 in set of Node

if (d[w]>d[v]+ c[v][w]) {

d[w] = d[v]+c[v][w];

}

S = w;// add 2 in set of Node

g.drawString("Total Distance = "+d[w],500, 150 );

g.drawString("Set of Node are 1,3,2" ,200, 150 );

}

anny_warda at 2007-7-16 4:18:53 > top of Java-index,Other Topics,Algorithms...