Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void dfs() {
- E[] nodes = (E[]) new Object[num_nodes];
- Stack<GraphNode<E>> pom = new Stack<GraphNode<E>>();
- ArrayList<GraphNode<E>> checked = new ArrayList<GraphNode<E>>();
- pom.push(adjList[0]);
- for (int i = 0; i < num_nodes; i++) {
- GraphNode<E> tmp = pom.pop();
- izvadi(tmp.info);
- nodes[i] = tmp.info;
- checked.add(tmp);
- oznaci(tmp.info);
- pecati(tmp.info);
- for (GraphNodeNeighbor<E> neigh : tmp.neighbors) {
- if (!checked.contains(neigh.node)) {
- pom.push(neigh.node);
- dodadi(neigh.node.info);
- } else {
- odmini(neigh.node.info);
- }
- }
- System.out.println();
- }
- // for (int i = 0; i < nodes.length; i++) {
- // System.out.print(nodes[i]);
- // }
- }
- private void izvadi(E x) {
- System.out.println("== VADEME: " + x);
- }
- private void dodadi(E x) {
- System.out.println("== STAVAME: " + x);
- }
- private void pecati(E x) {
- System.out.println("== PECATI: " + x);
- }
- private void oznaci(E x) {
- System.out.println("== OZNACI: " + x);
- }
- private void odmini(E x) {
- System.out.println("== ODMINI: " + x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement