public class Vertex
extends java.lang.Object
TopologicalSort can work on.| Constructor and Description |
|---|
Vertex(java.lang.Object userObject)
Constructor that wraps a node in the graph that has to be sorted.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAdjacentVertex(Vertex vertex)
Adds a dependent vertex to this vertex.
|
boolean |
equals(java.lang.Object obj) |
java.lang.Object |
getUserObject()
Returns the application's graph node that was wrapped by this vertex.
|
int |
hashCode() |
public Vertex(java.lang.Object userObject)
The userObject must implement reasonable equals()
and hashCode() methods.
userObject - the application's graph node, to be retrieved later
through getUserObject()public void addAdjacentVertex(Vertex vertex)
The direction of the graph is from "must occur first" to "may occur later".
If node B depends on node A, then call vertexA.addAdjacentVertex(vertexB).
To use the example from Cormen, if you want to figure out in which order to put on your clothes, the vertex for socks must point to the vertex for shoes, stating that socks must be put on before you can put on your shoes, or in other words, that shoes depend on socks. So add the shoe vertex to the sock's adjacent vertex list.
vertex - another vertex that depends on this vertex.public java.lang.Object getUserObject()
public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object