Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
56 lines (48 loc) · 1.38 KB

File metadata and controls

56 lines (48 loc) · 1.38 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package leetcode.common;
import java.util.Scanner;
/**
* @author 刘壮飞
* https://github.com/zfman.
* https://blog.csdn.net/lzhuangfei.
*/
public class GraphUtils {
/**
* 无向图输入
*/
public static AMGraph cin(){
Scanner scanner = new Scanner(System.in);
System.out.println("顶点数 边数:");
int vexNum = scanner.nextInt();
int arcNum = scanner.nextInt();
int[] vexs = new int[vexNum + 1];
int[][] arcs = new int[vexNum + 1][vexNum + 1];
for (int i = 1; i <= vexNum; i++) {
vexs[i] = i;
}
System.out.println("顶点1 顶点2(表示1-2有一条边):");
for (int i = 1; i <= arcNum; i++) {
int pos1 = scanner.nextInt();
int pos2 = scanner.nextInt();
arcs[pos1][pos2] = 1;
arcs[pos2][pos1] = 1;
}
AMGraph graph=new AMGraph();
graph.arcs=arcs;
graph.vexNum=vexNum;
graph.arcNum=arcNum;
return graph;
}
/**
* 输出
* @param graph
*/
public static void print(AMGraph graph){
if(graph.arcs==null) return;
int[][] arcs=graph.arcs;
for (int i = 1; i < arcs.length; i++) {
for (int j = 1; j < arcs[i].length; j++)
System.out.print(arcs[i][j] + " ");
System.out.println();
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.