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

📄 demosearchgraphuos.java

📁 国外的数据结构与算法分析用书
💻 JAVA
字号:
/* DemoSearchGraphLinkedRepUos
 * ---------------------------------------------
 * Copyright (c) 2002 University of Saskatchewan
 * All Rights Reserved
 * -------------------------------------------- */
 
 package dslib.demo;
 
 import dslib.graph.*;
 import dslib.exception.*;
 import java.io.*;
 
 /** Basic setup for the graph files. **/
  public class DemoSearchGraphUos extends DemoGraphUos
 {
	/**  Performs the demo on the graph passed to it.
		Note that this destroys the graph. 
		@param g The graph to be demo-ed. */
	public DemoSearchGraphUos(GraphUos g)
	{
		super(g);
		// place the output in a text file that reflects the class being demonstrated.
		String className = g.getClass().getName();
		className = className.substring(className.lastIndexOf(".")+1);
		PrintWriter out = null;
		FileOutputStream fo = null;
		try
		{
			fo = new FileOutputStream("OutputDemo" + className + ".txt", true);
			out = new PrintWriter(fo);
		} catch (Exception e)
		{
			System.err.println("Error creating output file in test routine for " + className);
			e.printStackTrace();
		}
		g.fileRead("dslib/demo/graphuosdata.txt");
		out.println("Testing Search Features");
		if (g instanceof SearchGraphLinkedRepUos)
		{
			((SearchGraphLinkedRepUos)g).goIth(1);
			SearchVertexUos v1 = (SearchVertexUos)g.item(); 
			/* System.setOut directs the output to the specified location.  In this case, we
			want all output to the file, but dfs & bfs methods print it to console so we must
			redirect it to the file using setOut. */
			PrintStream stdOut = System.out;
			System.setOut(new PrintStream(fo));
			out.println("Depth first search:");
			out.flush();
			((SearchGraphLinkedRepUos)g).dfsTrace(v1);
			out.println("\nBreadth first search:");
			out.flush();
			((SearchGraphLinkedRepUos)g).bfsTrace(v1);
			System.setOut(stdOut);
			out.println();
			out.close();
		}
		else 
		{
			((SearchGraphMatrixRepUos)g).goIth(1);
			SearchVertexUos v1 = (SearchVertexUos)g.item(); 
			/* System.setOut directs the output to the specified location.  In this case, we
			want all output to the file, but dfs & bfs methods print it to console so we must
			redirect it to the file using setOut. */
			PrintStream stdOut = System.out;
			System.setOut(new PrintStream(fo));
			out.println("Depth first search:");
			out.flush();
			((SearchGraphMatrixRepUos)g).dfsTrace(v1);
			out.println("\nBreadth first search:");
			out.flush();
			((SearchGraphMatrixRepUos)g).bfsTrace(v1);
			System.setOut(stdOut);
			out.println();
			out.close();
		}

	}
}
	

⌨️ 快捷键说明

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