?? topological.java~113~
字號:
package course;
import java.util.Stack;
/**
* <p>Title: 拓撲排序</p>
*
* <p>Description: 實現拓撲排序</p>
*
* <p>Copyright: Copyright (c) 2007 </p>
*
* <p>Company: www.bchine.com</p>
*
* @author 李丕績
* @version 1.0
*/
public class Topological extends Adjacency {
Stack S = new Stack();
Adjacency ad = new Adjacency();
Field fi[];
Field eld = new Field();
Field f = new Field();
public static int t;
public boolean Topo(Field v[], int n, int aa[][]) {
fi=new Field[ n];
ad.InitializePos(n); //初始化數組pos作為中間橋梁的作用
int InDegree[] = new int[n + 1];
for (int i = 1; i <= n; i++) {
InDegree[i] = 0; //初始化入度
}
for (int i = 1; i <= n; i++) {
int u = ad.Begin(i, aa);
System.out.println(u + "a");
while (u != 0) {
InDegree[u]++;
u = NextVertex(i, aa);
System.out.println(u + "b");
}
}
for (int i = 1; i <= n; i++) {
fi[i-1]=new Field() ;
if (InDegree[i] == 0) {
fi[i-1].index = i;
fi[i-1].term = 1;
System.out.println(fi[i-1].index + "入棧");
S.push(fi[i-1]);
}
}
System.out.println(((Field)S.pop()).index);
System.out.println(((Field)S.pop()).index);
int a= 0;
// while (!S.empty()) {
// Field b = (Field) S.pop();
// v[a++] = b;
// int w = b.index;
// System.out.println(w + "出棧");
// int u = Begin(w, aa);
// while (u != 0) {
// InDegree[u]--;
// if (InDegree[u] == 0) {
// f.index = u;
// f.term = b.term + 1;
// System.out.println(u + "入棧");
// S.push(f);
// }
// u = NextVertex(w, aa);
// }
// }
return (a == n);
}
public static void main(String[] args) {
Topological top = new Topological();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -