⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphprogram1.java

📁 A class on for undirected graphs. Tester is available
💻 JAVA
字号:

import java.io.*;


public class GraphProgram1 {
	
	
	
	public static void main(String[] args)  throws IOException {
		
		BufferedReader stdin = new BufferedReader(new FileReader("graph.in"));
		
		String input = stdin.readLine();
		
		int number = Integer.parseInt(input);
		
		int[] list = new int[number+1];
		Graph theGraph = new Graph(number);
				
		while (stdin.ready()) {
			input = stdin.readLine();
			String[] tokens = input.split(" ");
			
			int num1 = Integer.parseInt(tokens[0]);
			int num2 = Integer.parseInt(tokens[1]);
			
		
			Vertex v1 = new Vertex(num1);
			Vertex v2 = new Vertex(num2);
			
			if(!search(list,v1.el)) {
				list[num1]=1;
				theGraph.incrementVertices();
			}
						
			if(!search(list,v2.el)) {
				list[num2]=1;
				theGraph.incrementVertices();
			}
			
			Edge e1 = new Edge(v1, v2);
			
			theGraph.addEdge(e1);	
		}
	    
	    theGraph.displayMatrix(); 
	    	
		System.out.println();
		System.out.println("No. of vertices = " + theGraph.getVertices());
		System.out.println("No. of edges = " + theGraph.getEdges());
		
		
	}  //end main
	
		
	static boolean search(int[] list, int number) {
		if(list[number] == 1)
			return true;
		return false;
	}
}  //end GraphProgram1


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -