?? adjacency.java~93~
字號(hào):
package course;
/**
* <p>Title:鄰接矩陣 </p>
*
* <p>Description: 建立鄰接矩陣及其基本方法</p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company:www.bchine.com </p>
*
* @author lipiji
* @version 1.0
*/
public class Adjacency {
int noEdge = 0;
public static int n;
int e = 0;
public static int pos[];
void InitializePos(int i) {
pos = new int[i + 1];
}
void DeactivatePos(int n) {
for (int i = 0; i <= n; i++) {
pos[i] = 0;
}
}
public void makeAdjacency(int Vertices, int noEdge, int a[][]) {
this.n = Vertices;
e = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
a[i][j] = noEdge;
}
}
}
//檢查是否已經(jīng)存在
public Boolean Exist(int i, int j, int a[][]) {
if (i < 1 || j < 1 || i > n || j > n
|| a[i][j] == noEdge) {
return false;
}
return true;
}
public void Add(int i, int j, int w, int a[][]) {
if (i < 1 || j < 1 || i > n ||
j > n || i == j || a[i][j] != noEdge) {
System.out.println("Add throw BadInput();");
}
a[i][j] = w;
e++;
}
public void Delete(int i, int j, int a[][]) {
if (i < 1 || j < 1 || i > n ||
j > n || a[i][j] == noEdge) {
System.out.println("Delete throw BadInput();");
}
a[i][j] = noEdge;
e--;
}
public int OutDegree(int i, int a[][]) {
if (i < 1 || i > n) {
System.out.println("OutDegree throw BadInput();");
}
int sum = 0;
for (int j = 1; j <= n; j++) {
if (a[i][j] != noEdge) {
sum++;
}
}
return sum;
}
public int InDegree(int i, int a[][]) {
if (i < 1 || i > n) {
System.out.println("InDegree throw BadInput();");
}
int sum = 0;
for (int j = 1; j <= n; j++) {
if (a[j][i] != noEdge) {
sum++;
}
}
return sum;
}
int Begin(int i, int a[][]) {
if (i < 1 || i > n) {
System.out.println("Begin throw BadInput();" + i);
}
int j = 0;
for (j = 1; j <= n; j++) {
if (a[i][j] != noEdge) {
pos[i] = j;
return j;
}
}
pos[i] = n + 1;
return 0;
}
public int NextVertex(int i, int a[][]) {
if (i < 1 || i > n) {
System.out.println("NextVertex throw BadInput();" + i);
}
for (int j = pos[i] + 1; j <= n; j++) {
if (a[i][j] != noEdge) {
pos[i] = j;
return j;
}
}
pos[i] = n + 1;
return 0;
}
public void Output(int a[][]) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
public static void main(String[] args) {
Adjacency adjacency = new Adjacency();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -