AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
IterativeDFS2.java
Go to the documentation of this file.
1package aud.example.graph;
2
3import aud.Stack;
4
25public class IterativeDFS2 extends Traversal {
26
28 super(g);
29 }
30
31 @Override public String name() { return "iterative DFS (decently cheating)"; }
32
33 @Override public void start(MyNode s0) {
34 initialize(); // reset all node attributes
35
36 int count=0;
38 s0.ord=count++; // marked
39 s0.d=0.0;
40
41 showMark(s0);
42 open.push(s0);
43
44 while (!open.is_empty()) {
45 if (verbose>0)
46 System.out.println("open="+open.toString());
47
48 MyNode s=open.pop();
49
50 showVisit(s);
51
52 for (MyEdge e : g_.getOutEdges(s)) {
53
54 if (verbose>1)
55 System.err.println(e);
56
57 MyNode t=(MyNode) e.destination();
58 if (t==s)
59 t=(MyNode) e.source(); // undirected graph
60
61 if (t.ord<0) { // <=> not marked
62 t.ord=count++;
63 t.p=s;
64 t.d=s.d+(e.hasWeight() ? e.getWeight() : 1.0);
65
66 showMark(t);
67
68 open.push(t);
69 }
70 }
71 }
72 }
73
74}
Implementation of a stack based on aud.Vector.
Definition: Stack.java:8
void push(T x)
Push x onto stack.
Definition: Stack.java:31
boolean is_empty()
Is stack empty?
Definition: Stack.java:14
T pop()
Pop element from stack.
Definition: Stack.java:23
String toString()
Get string representation "|a|b|c".
iterative implementation of DFS Traversal like DepthFirstSearch but as for IterativeDFS1 the order of...
void start(MyNode s0)
start traversal at node s0
String name()
get traversal name
edge with all possible attributes that we require ;-)
Definition: MyEdge.java:6
graph based on aud.graph.GraphAM
Definition: MyGraph.java:11
node with all possible attributes that we require ;-)
Definition: MyNode.java:6
MyNode p
node from which node was reached (defines spanning tree)
Definition: MyNode.java:16
double d
distance to start node (sum of weighs or edge count if no weights defined)
Definition: MyNode.java:21
int ord
time when node is (first marked/put into front)
Definition: MyNode.java:13
interface for traversals of MyGraph
Definition: Traversal.java:6
int verbose
set verbosity (extra output if >0)
Definition: Traversal.java:15
void initialize()
initialize graph for traversal (reset all attributes), provided for convenience to be called by start
Definition: Traversal.java:34
void showMark(MyNode node)
callback to give visual feedback on marking a node
Definition: Traversal.java:44
Vector< Edge > getOutEdges(Node node)
Definition: GraphAM.java:98
AuD lecture: Data structures, algorithms, examples.
Definition: A234Tree.java:1