|
| | PointerGraph (void)=default |
| | the empty graph
|
| | PointerGraph (const PointerGraph &)=delete |
| | no copy, since the nodes are linked by pointers
|
| PointerGraph & | operator= (const PointerGraph &)=delete |
| | no copy, since the nodes are linked by pointers
|
| int | n (void) const |
| | the number of nodes
|
| Node * | insertNode (const T &t) |
| | a new isolated node of label \( t \)
|
| Node * | find (const T &t) |
| | the first node of label \( t \), nullptr if none
|
| bool | hasEdge (const Node *u, const Node *v) const |
| void | insertEdge (Node *u, Node *v, const W &w=W()) |
| | the edge \( ( u , v ) \) of weight \( w \), if not there
|
| void | deleteEdge (Node *u, Node *v) |
| bool | deleteNode (Node *u) |
| | deletes \( u \) if isolated; false otherwise
|
| void | forceDeleteNode (Node *u) |
| | deletes the edges of \( u \) and then \( u \)
|
| std::vector< Node * > | adjacent (const Node *u) const |
| | the nodes adjacent to \( u \)
|
| template<class F> |
| void | dfs (Node *r, F &&f) |
| | the depth first visit from \( r \), \( f \) on each node reached
|
| template<class F> |
| void | bfs (Node *r, F &&f) |
| | the breadth first visit from \( r \)
|
template<class T, class W = int>
class ADS::PointerGraph< T, W >
an oriented graph of node objects linked by pointers
template<class T, class W = int>
template<class F>
the breadth first visit from \( r \)
In pseudocode (section 9.5), the flags of the nodes cleared first:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{bfs}( r , f ) \cr
2 & \quad r.\mathit{flag} \gets \textbf{true};\ Q \gets ( r )\quad
\triangleright\ \text{marked on entering } Q \cr
3 & \quad \textbf{while}\ Q \ne \emptyset\ \textbf{do} \cr
4 & \qquad u \gets \mathrm{dequeue}( Q );\ f( u ) \cr
5 & \qquad \textbf{foreach}\ v \in \mathrm{adjacent}( u )
\text{ with no flag}\ \textbf{do}\ v.\mathit{flag} \gets
\textbf{true};\ \mathrm{enqueue}( Q , v )
\end{array}}
\]
- Precondition
- \( r \) is a node of the graph
template<class T, class W = int>
template<class F>
the depth first visit from \( r \), \( f \) on each node reached
In pseudocode (section 9.5), the flags of the nodes cleared first:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{dfs}( r , f )\quad \triangleright
\ \text{the flag of a node marks it reached} \cr
2 & \quad r.\mathit{flag} \gets \textbf{true};\ f( r ) \cr
3 & \quad \textbf{foreach}\ v \in \mathrm{adjacent}( r )\ \textbf{do}
\ \textbf{if}\ \textbf{not}\ v.\mathit{flag}\ \textbf{then}
\ \mathrm{dfs}( v , f )
\end{array}}
\]
- Precondition
- \( r \) is a node of the graph
template<class T, class W = int>
deletes the edges of \( u \) and then \( u \)
In pseudocode:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{forceDeleteNode}( u ) \cr
2 & \quad \textbf{foreach}\ x \in V\ \textbf{do}\ \text{remove the edge }
\text{from } x \text{ to } u \text{ , if there is one} \cr
3 & \quad \text{remove the edges of } u;\ \mathrm{deleteNode}( u )
\end{array}}
\]
- Precondition
- \( u \) is a node of the graph