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

📄 cyclegraphlinkedrepuos.java

📁 国外的数据结构与算法分析用书
💻 JAVA
字号:
import dslib.graph.*;

/**	A directed search graph with a function to determine whether 
	a specified vertex is within a cycle.  */
public class CycleGraphLinkedRepUos extends SearchGraphLinkedRepUos
{
	/**	Construct a new directed graph with capacity for up to cap vertices.
		Analysis: Time  = O(cap) */
	public CycleGraphLinkedRepUos(int cap)
	{
		super(cap);
		directed = true;
	}

	/**	Is there a cycle that includes s?
		Analysis: Time = O(n + m) */
	public boolean isInCycle(SearchVertexUos s)
	{
		setAllUnreached();
		return scanForPath(s, s);
	}

	/**	Test for a path from p that ends with an edge back to the origin vertex.
		Analysis: Time = O(n + m), where n = number of vertices, m = number of edges */
	public boolean scanForPath(SearchVertexUos p, SearchVertexUos origin)
	{
		GraphPositionUos position = currentPosition();
		boolean found = false;
		p.setReached(true);
		eGoFirst(p);
		while (!found & !eAfter())
			if (!((SearchVertexUos)adjItem()).reached())
			{
				/*	Continue the search from the unreached adjacent vertex. */
				found = scanForPath((SearchVertexUos)adjItem(), origin);
				if (!found)
					eGoForth();
			}
			else if (adjItem() == origin)
				found = true;
			else	
				/*	As adjacent vertex is reached, it has already been unsuccessfully searched. */
				eGoForth();
		goPosition(position);
		return found;
	}
}

⌨️ 快捷键说明

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