呵呵,最短路径算法,忘光光不过 JS 很是能看懂的,LZ 的代码在实例化 Point 时只能初始化 id 一个属性,相邻节点数目以及相邻节点集合根本没有初始化,不知道 LZ 何时处理其它属性。至少应该这个样子吧?// 相邻节点数组。
var nextPoints = new Array(p1, p3, p5);// 如果不喜欢数组,就直接传入,用 arguments 获取。
function Point(n, nextPoints){
var i;
this.id=n;
this.nextnum=nextPoints.length;
this.ed=null;
for(i=0;i<this.nextnum;i++){
this.next[i]_id=nextPoints[i].id;
this.next[i]_dis=nextPoints[i].dis;
this.next[i]_weight=nextPoints[i].weight;
}
}
var nextPoints = new Array(p1, p3, p5);// 如果不喜欢数组,就直接传入,用 arguments 获取。
function Point(n, nextPoints){
var i;
this.id=n;
this.nextnum=nextPoints.length;
this.ed=null;
for(i=0;i<this.nextnum;i++){
this.next[i]_id=nextPoints[i].id;
this.next[i]_dis=nextPoints[i].dis;
this.next[i]_weight=nextPoints[i].weight;
}
}
thanks
thanks very much
大一些的象 prototype jquery Yahoo UI 这些.都是蛮经典的OOP源码.