-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Fabrizio
authored and
Fabrizio
committed
Jan 29, 2017
1 parent
42687bb
commit 699b030
Showing
13 changed files
with
158 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>Strategy</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
public class ContextVisit<T> { | ||
|
||
private Visit<T> visit; | ||
|
||
private Node<T> root; | ||
|
||
public ContextVisit(Node<T> root) { | ||
this.root = root; | ||
} | ||
|
||
public void setRoot(Node<T> root) { | ||
this.root = root; | ||
} | ||
|
||
public void setVisit(Visit<T> visit) { | ||
this.visit = visit; | ||
} | ||
|
||
public void visit() { | ||
visit.visit(root); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
public class DeepVisit<T> implements Visit<T> { | ||
|
||
@Override | ||
public void visit(Node<T> root) { | ||
System.out.print(root); | ||
for(Node<T> node: root.getChildren()) | ||
visit(node); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import java.util.ArrayList; | ||
|
||
public class LevelVisit<T> implements Visit<T> { | ||
|
||
@Override | ||
public void visit(Node<T> root) { | ||
ArrayList<Node<T>> queue = new ArrayList<Node<T>>(); | ||
queue.add(root); | ||
while(!queue.isEmpty()) { | ||
System.out.print(queue.get(0)); | ||
queue.addAll(queue.get(0).getChildren()); | ||
queue.remove(0); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
Node<Integer> node = new Node<Integer>(1); | ||
Node<Integer> node1 = new Node<Integer>(2); | ||
Node<Integer> node2 = new Node<Integer>(3); | ||
Node<Integer> node3 = new Node<Integer>(4); | ||
Node<Integer> node4 = new Node<Integer>(5); | ||
Node<Integer> node5 = new Node<Integer>(6); | ||
Node<Integer> node6 = new Node<Integer>(7); | ||
Node<Integer> node7 = new Node<Integer>(8); | ||
node.addChildren(node1); | ||
node.addChildren(node2); | ||
node1.addChildren(node3); | ||
node1.addChildren(node4); | ||
node2.addChildren(node5); | ||
node2.addChildren(node6); | ||
node3.addChildren(node7); | ||
|
||
ContextVisit<Integer> contextVisit = new ContextVisit<Integer>(node); | ||
contextVisit.setVisit(new DeepVisit<Integer>()); | ||
contextVisit.visit(); | ||
System.out.println(); | ||
contextVisit.setVisit(new LevelVisit<Integer>()); | ||
contextVisit.visit(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import java.util.ArrayList; | ||
|
||
public class Node<T> { | ||
|
||
private T value; | ||
|
||
private ArrayList<Node<T>> children; | ||
|
||
@SuppressWarnings("unchecked") | ||
public Node(T value){ | ||
this.value = value; | ||
children = (ArrayList<Node<T>>) new ArrayList<T>(); | ||
} | ||
|
||
public ArrayList<Node<T>> getChildren() { | ||
return children; | ||
} | ||
|
||
public T getValue() { | ||
return value; | ||
} | ||
|
||
public void addChildren(Node<T> node) { | ||
children.add(node); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[" + value + "]"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
public interface Visit<T> { | ||
|
||
public void visit(Node<T> root); | ||
|
||
} |