Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

×îСÉú³ÉÊ÷ KruskalËã·¨ java´úÂëʵÏÖ

/*
*ÈÕÆÚ:2010-04-18 20:02
*¿ª·¢Õß:heroyan
*ÁªÏµ·½Ê½:zndxysf@126.com
*¹¦ÄÜ:ÎÞÏòͼ×îСÉú³ÉÊ÷KruskalË㷨ʵÏÖ°¸Àý
*/
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
public class Kruskal{
private static int MAX = 100;
private ArrayList<Edge> edge = new ArrayList<Edge>();//Õû¸öͼµÄ±ß
private ArrayList<Edge> target = new ArrayList<Edge>();//Ä¿±ê±ß£¬×îСÉú³ÉÊ÷
private int[] parent = new int[MAX];//±êÖ¾ËùÔڵļ¯ºÏ
private static double INFINITY = 99999999.99;//¶¨ÒåÎÞÇî´ó
private double mincost = 0.0;//×îС³É±¾
private int n;//½áµã¸öÊý

public Kruskal(){}

public static void main(String args[]){
Kruskal sp = new Kruskal();
sp.init();
sp.kruskal();
sp.print();
}
//³õʼ»¯
public void init(){
Scanner scan = new Scanner(System.in);
int p,q;
double w;

System.out.println("spanning tree begin!Input the node number:");
n = scan.nextInt();
System.out.println("Input the graph(-1,-1,-1 to exit)");

while(true){
p = scan.nextInt();
q = scan.nextInt();
w = scan.nextDouble();
if(p < 0 || q < 0 || w < 0){
break;
}
Edge e = new Edge();
e.start = p;
e.end = q;
e.cost = w;
edge.add(e);
}

mincost = 0.0;

for(int i = 1; i <= n; ++i){
parent[i] = i;
}
}
//¼¯ºÏºÏ²¢
public void union(int j, int k){
for(int i = 1; i <= n; ++i){
if(parent[i] == j){
parent[i] = k;
}
}
}
//primËã·¨Ö÷Ìå
public void kruskal(){
//ÕÒʣϵÄn-2Ìõ±ß
int i = 0;
while(i < n-1 && edge.size() > 0){
//ÿ´ÎÈ¡Ò»×îС±ß£¬²¢É¾³ý
double min = INFINITY;
int tag = 0;
Edge tmp = null;
for(int j = 0; j < edge.size(); ++j){
Edge tt = edge.get(j);
if(tt.cost < min){
min = tt.cost;
tmp = tt;
}
}
int jj = parent[tmp.start];
int kk = parent[tmp.end];
//È¥µô»·
if(jj != kk){
++i;
target.add(tmp);
m


Ïà¹ØÎĵµ£º

JavaÖÐtoArrayµÄÓ÷¨Ì½¾¿(javaÊý×éÓëlistת»»)


Ò»£®             Incident
import java.util.ArrayList;  
import java.util.List;  
public class Test {  
    public static void main(String[] args) {  
     ......

JAVAºÍJSPÖ®¼äµÄ¹Øϵ

ÎÒÏÖÔÚ¸øÄãÒ»¸öJAVAºÍJSPÖ®¼äµÄ¹Øϵ,ÒÔ¼°JAVAµÄÍêÕûÈÏʶ
JAVA·ÖΪJ2EE,J2SE.J2ME,ÏÂÃæ·Ö±ð½éÉÜ:
Ò».J2EE£ºJava 2 Platform Enterprise Edition ÆóÒµ°æ£¬ÓÃÓÚÆóÒµÓ¦Óã¬Ö§³Ö·Ö²¼Ê½²¿Êð¡£ 
J2EEƽ̨ÓÉÒ»ÕûÌ×·þÎñ£¨Services£©¡¢Ó¦ÓóÌÐò½Ó¿Ú£¨APIs£©ºÍЭÒé¹¹³É£¬
Ëü¶Ô¿ª·¢»ùÓÚWebµÄ¶à²ãÓ¦ÓÃÌṩÁ˹¦ÄÜÉϵÄÖ§³Ö¡£Ëü°ü ......

µÚ1ÕÂ Java»ù´¡

µÚ1ÕÂ
 
Java»ù´¡
 
1.1            JavaµÄÀúÊ·ºÍ»ù±¾Ô­Àí
1.2            Java×Ö½ÚÂë
1.3            JavaÊõÓï
1.4 &nbs ......

java¶ÔÏóÐòÁл¯Ñ§Ï°±Ê¼Ç

    ÐòÁл¯µÄ¹ý³Ì¾ÍÊǶÔÏóдÈë×Ö½ÚÁ÷ºÍ´Ó×Ö½ÚÁ÷ÖжÁÈ¡¶ÔÏó¡£½«¶ÔÏó״̬ת»»³É×Ö½ÚÁ÷Ö®ºó£¬¿ÉÒÔÓÃjava.io°üÖеĸ÷ÖÖ×Ö½ÚÁ÷ÀཫÆä±£´æµ½ÎļþÖУ¬¹ÜµÀµ½ÁíÒ»Ïß³ÌÖлòͨ¹ýÍøÂçÁ¬½Ó½«¶ÔÏóÊý¾Ý·¢Ë͵½ÁíÒ»Ö÷»ú¡£¶ÔÏóÐòÁл¯¹¦Äܷdz£¼òµ¥¡¢Ç¿´ó£¬ÔÚRMI¡¢Socket¡¢JMS¡¢EJB¶¼ÓÐÓ¦Ó᣶ÔÏóÐòÁл¯ÎÊÌâÔÚÍøÂç±à³ÌÖв¢²»ÊÇ× ......

Javaѧϰ ´ÓÈëÃŵ½¾«Í¨


Java Learning Path £¨Ò»£©¡¢¹¤¾ßƪ
Ò»¡¢ JDK (Java Development Kit)
JDKÊÇÕû¸öJavaµÄºËÐÄ£¬°üÀ¨ÁËJavaÔËÐл·¾³£¨Java Runtime Envirnment£©£¬Ò»¶ÑJava¹¤¾ßºÍJava»ù´¡µÄÀà¿â(rt.jar)¡£²»ÂÛʲôJavaÓ¦Ó÷þÎñÆ÷ʵÖʶ¼ÊÇÄÚÖÃÁËij¸ö°æ±¾µÄJDK¡£Òò´ËÕÆÎÕJDKÊÇѧºÃJavaµÄµÚÒ»²½¡£×îÖ÷Á÷µÄJDKÊÇSun¹«Ë¾·¢²¼µÄJDK£¬³ýÁËSunÖ®Íâ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ