T
- the data type of this vertexpublic class VertexTree<T> extends Object implements RootedTree<VertexTree<T>,Arc<VertexTree<T>>>
VertexTree
is both a tree and a vertex/node.This implementation builds a tree
incrementally and recursively (combining trees).Constructor and Description |
---|
VertexTree(T t) |
Modifier and Type | Method and Description |
---|---|
VertexTree<T> |
addEdge(Arc<VertexTree<T>> e)
Adds an edge to this graph.
|
VertexTree<T> |
addVertex(VertexTree<T> v)
Adds a vertex to this graph.
|
Set<VertexTree<T>> |
children(VertexTree<T> v)
Gets the set of all children of this vertex.
|
T |
data() |
int |
depth(VertexTree<T> v)
Gets the (unweighted) distance of a vertex from the root of the vertex.
|
Set<Arc<VertexTree<T>>> |
edges()
Gets the set of all edges in this graph.
|
Set<Arc<VertexTree<T>>> |
edges(VertexTree<T> v)
Gets the set of all edges associated with a vertex in this graph.
|
static <T> List<Integer> |
findPosition(VertexTree<T> node)
Finds the position of a node from its tree root recursively.
|
int |
height()
Gets the maximum depth in this tree.
|
Set<Arc<VertexTree<T>>> |
incomingArcs(VertexTree<T> v)
Gets the set of all incoming arcs associated with a vertex in this graph.
|
Set<Arc<VertexTree<T>>> |
outgoingArcs(VertexTree<T> v)
Gets the set of all outgoing arcs associated with a vertex in this graph.
|
VertexTree<T> |
parent(VertexTree<T> v)
Gets the unique parent of a vertex.
|
Set<VertexTree<T>> |
parents(VertexTree<T> v)
Gets the set of all parents of this vertex.
|
VertexTree<T> |
removeEdge(Arc<VertexTree<T>> e)
Removes an edge from this graph.
|
VertexTree<T> |
removeVertex(VertexTree<T> v)
Removes a vertex from this graph.
|
VertexTree<T> |
root()
Gets the root of this tree.
|
RootedTree<VertexTree<T>,Arc<VertexTree<T>>> |
subTree(VertexTree<T> v)
Gets a sub-tree starting from a vertex.
|
int |
topologicalOrder(VertexTree<T> v)
Get the topological order of a vertex.
|
String |
toString() |
Set<VertexTree<T>> |
vertices()
Gets the set of all vertices in this graph.
|
public VertexTree(T t)
public static <T> List<Integer> findPosition(VertexTree<T> node)
node
- public T data()
public Set<VertexTree<T>> parents(VertexTree<T> v)
DiGraph
parents
in interface DiGraph<VertexTree<T>,Arc<VertexTree<T>>>
v
- a vertexpublic Set<VertexTree<T>> children(VertexTree<T> v)
DiGraph
children
in interface DiGraph<VertexTree<T>,Arc<VertexTree<T>>>
v
- a vertexpublic VertexTree<T> root()
RootedTree
root
in interface RootedTree<VertexTree<T>,Arc<VertexTree<T>>>
public int depth(VertexTree<T> v)
RootedTree
depth
in interface RootedTree<VertexTree<T>,Arc<VertexTree<T>>>
v
- the vertex whose depth is to be computedpublic int height()
RootedTree
height
in interface RootedTree<VertexTree<T>,Arc<VertexTree<T>>>
public RootedTree<VertexTree<T>,Arc<VertexTree<T>>> subTree(VertexTree<T> v)
RootedTree
subTree
in interface RootedTree<VertexTree<T>,Arc<VertexTree<T>>>
v
- the root of the sub-treepublic VertexTree<T> parent(VertexTree<T> v)
Tree
parent
in interface Tree<VertexTree<T>,Arc<VertexTree<T>>>
v
- a vertexv
public Set<VertexTree<T>> vertices()
Graph
vertices
in interface Graph<VertexTree<T>,Arc<VertexTree<T>>>
public Set<Arc<VertexTree<T>>> edges()
Graph
edges
in interface Graph<VertexTree<T>,Arc<VertexTree<T>>>
public Set<Arc<VertexTree<T>>> edges(VertexTree<T> v)
Graph
edges
in interface Graph<VertexTree<T>,Arc<VertexTree<T>>>
v
- a vertexpublic VertexTree<T> addVertex(VertexTree<T> v)
Graph
v
is already in the graph.addVertex
in interface Graph<VertexTree<T>,Arc<VertexTree<T>>>
v
- the vertex to addpublic VertexTree<T> addEdge(Arc<VertexTree<T>> e)
Graph
e
is already in the graph.
If the edge contains new vertices, those will be added to the graph.addEdge
in interface Graph<VertexTree<T>,Arc<VertexTree<T>>>
e
- the edge to addpublic VertexTree<T> removeVertex(VertexTree<T> v)
Graph
v
is not in the graph.
The edges associated with this vertex are also removed.removeVertex
in interface Graph<VertexTree<T>,Arc<VertexTree<T>>>
v
- the vertex to be removedpublic VertexTree<T> removeEdge(Arc<VertexTree<T>> e)
Graph
e
is not in the graph.
The vertices associated with the edge is not removed.removeEdge
in interface Graph<VertexTree<T>,Arc<VertexTree<T>>>
e
- the edge to be removedpublic int topologicalOrder(VertexTree<T> v)
DAGraph
topologicalOrder
in interface DAGraph<VertexTree<T>,Arc<VertexTree<T>>>
v
- a vertexpublic Set<Arc<VertexTree<T>>> outgoingArcs(VertexTree<T> v)
DiGraph
outgoingArcs
in interface DiGraph<VertexTree<T>,Arc<VertexTree<T>>>
v
- a vertexpublic Set<Arc<VertexTree<T>>> incomingArcs(VertexTree<T> v)
DiGraph
incomingArcs
in interface DiGraph<VertexTree<T>,Arc<VertexTree<T>>>
v
- a vertexCopyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.