📄 adjacency.java~82~
字号:
package course;
/**
* <p>Title:邻接矩阵 </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Adjacency {
int noEdge = 0;
int n = 0;
int e = 0;
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;
}
}
void setVertices(int i) {
}
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;
}
}
}
//检查是否已经存在
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 > 6) {
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[][]) {
System.out.println("NextVertex throw BadInput();"+this.n);
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;
} else {
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();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -