📄 edgeuos.java
字号:
/* EdgeUos.java
* ---------------------------------------------
* Copyright (c) 2001 University of Saskatchewan
* All Rights Reserved
* --------------------------------------------- */
package dslib.graph;
import dslib.base.*;
import dslib.exception.ItemNotFoundUosException;
/** An edge of a graph that has firstItem and secondItem as its ends. Method 'has'
tests whether a vertex is an end of the edge, and method 'other' returns the other end. */
public class EdgeUos extends PairUos
{
/** Construct a new Edge object. <br>
Anaysis: Time = O(1)
@param v1 initial vertex of the new edge
@param v2 terminal vertex of the new edge */
public EdgeUos(VertexUos v1, VertexUos v2)
{
super(v1, v2);
}
/** Determine if v is an item of the edge. <br>
Analysis: Time = O(1)
@param v vertex to determin whether it belongs to the edge */
public boolean has(VertexUos v)
{
return ((v == firstItem) || (v == secondItem));
}
/** The other item of the edge. <br>
Analysis: Time = O(1) <br>
PRECONDITION: <br>
<ul>
has(v)
</ul>
@param v vertex adjacent vertex to v via this edge */
public VertexUos other(VertexUos v) throws ItemNotFoundUosException
{
if (!has(v))
throw new ItemNotFoundUosException("Cannot return the other item since this vertex does not exist.");
if (firstItem == v)
return (VertexUos)secondItem;
else // must have (secondItem == v)
return (VertexUos)firstItem;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -