Documentation
This commit is contained in:
parent
c1b05097e3
commit
67e2f3c0c1
17 changed files with 127 additions and 0 deletions
BIN
docs/HW3-slides.pdf
Normal file
BIN
docs/HW3-slides.pdf
Normal file
Binary file not shown.
BIN
docs/HW4-slides.pdf
Normal file
BIN
docs/HW4-slides.pdf
Normal file
Binary file not shown.
BIN
docs/HW5-slides.pdf
Normal file
BIN
docs/HW5-slides.pdf
Normal file
Binary file not shown.
BIN
docs/hw0.pdf
Normal file
BIN
docs/hw0.pdf
Normal file
Binary file not shown.
BIN
docs/hw1/HW1-SS18.pdf
Normal file
BIN
docs/hw1/HW1-SS18.pdf
Normal file
Binary file not shown.
BIN
docs/hw1/HW1-SS18.pptx
Normal file
BIN
docs/hw1/HW1-SS18.pptx
Normal file
Binary file not shown.
49
docs/hw1/SimpleVisitor.java
Normal file
49
docs/hw1/SimpleVisitor.java
Normal file
|
@ -0,0 +1,49 @@
|
|||
import java.lang.*;
|
||||
|
||||
abstract class TreeNode {
|
||||
public int key;
|
||||
public TreeNode leftchild;
|
||||
public TreeNode rightchild;
|
||||
|
||||
public TreeNode(int k, TreeNode left, TreeNode right) {
|
||||
key = k;
|
||||
leftchild = left;
|
||||
rightchild = right;
|
||||
}
|
||||
}
|
||||
|
||||
class BlueNode extends TreeNode {
|
||||
public BlueNode(int k, TreeNode left, TreeNode right) { super(k, left, right); }
|
||||
}
|
||||
|
||||
class GreenNode extends TreeNode {
|
||||
public GreenNode(int k, TreeNode left, TreeNode right) { super(k, left, right); }
|
||||
}
|
||||
|
||||
class Visitor {
|
||||
public void visit(TreeNode node) {
|
||||
System.out.print(node.key + ": ");
|
||||
|
||||
if (node instanceof BlueNode)
|
||||
System.out.println("Blue");
|
||||
else if (node instanceof GreenNode)
|
||||
System.out.println("Green");
|
||||
|
||||
if (node.leftchild != null) visit(node.leftchild);
|
||||
if (node.rightchild != null) visit(node.rightchild);
|
||||
}
|
||||
}
|
||||
|
||||
public class SimpleVisitor {
|
||||
public static void main(String [] args) {
|
||||
TreeNode root = new BlueNode(1,
|
||||
new GreenNode(21,
|
||||
new BlueNode(31, null, null),
|
||||
new GreenNode(32, null, null)),
|
||||
new GreenNode(22,
|
||||
new BlueNode(33, null, null),
|
||||
new GreenNode(34, null, null)));
|
||||
Visitor v = new Visitor();
|
||||
v.visit(root);
|
||||
}
|
||||
}
|
62
docs/hw1/VisitorPattern.java
Normal file
62
docs/hw1/VisitorPattern.java
Normal file
|
@ -0,0 +1,62 @@
|
|||
import java.lang.*;
|
||||
|
||||
abstract class TreeNode {
|
||||
public int key;
|
||||
public TreeNode leftchild;
|
||||
public TreeNode rightchild;
|
||||
|
||||
public TreeNode(int k, TreeNode left, TreeNode right) {
|
||||
key = k;
|
||||
leftchild = left;
|
||||
rightchild = right;
|
||||
}
|
||||
|
||||
public abstract void accept(Visitor v);
|
||||
}
|
||||
|
||||
class BlueNode extends TreeNode {
|
||||
public BlueNode(int k, TreeNode left, TreeNode right) { super(k, left, right); }
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.blueNode(this);
|
||||
}
|
||||
}
|
||||
|
||||
class GreenNode extends TreeNode {
|
||||
public GreenNode(int k, TreeNode left, TreeNode right) { super(k, left, right); }
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.greenNode(this);
|
||||
}
|
||||
}
|
||||
|
||||
class Visitor {
|
||||
public void blueNode(BlueNode node) {
|
||||
System.out.print(node.key + ": ");
|
||||
System.out.println("Blue");
|
||||
|
||||
if (node.leftchild != null) node.leftchild.accept(this);
|
||||
if (node.rightchild != null) node.rightchild.accept(this);
|
||||
}
|
||||
|
||||
public void greenNode(GreenNode node) {
|
||||
System.out.print(node.key + ": ");
|
||||
System.out.println("Green");
|
||||
|
||||
if (node.leftchild != null) node.leftchild.accept(this);
|
||||
if (node.rightchild != null) node.rightchild.accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
public class VisitorPattern {
|
||||
public static void main(String [] args) {
|
||||
TreeNode root = new BlueNode(1,
|
||||
new GreenNode(21,
|
||||
new BlueNode(31, null, null),
|
||||
new GreenNode(32, null, null)),
|
||||
new GreenNode(22,
|
||||
new BlueNode(33, null, null),
|
||||
new GreenNode(34, null, null)));
|
||||
root.accept(new Visitor());
|
||||
}
|
||||
}
|
BIN
docs/hw1/hw1.pdf
Normal file
BIN
docs/hw1/hw1.pdf
Normal file
Binary file not shown.
BIN
docs/hw2/HW2-slides.pdf
Normal file
BIN
docs/hw2/HW2-slides.pdf
Normal file
Binary file not shown.
BIN
docs/hw2/hw2.pdf
Normal file
BIN
docs/hw2/hw2.pdf
Normal file
Binary file not shown.
BIN
docs/hw3.pdf
Normal file
BIN
docs/hw3.pdf
Normal file
Binary file not shown.
BIN
docs/hw4.pdf
Normal file
BIN
docs/hw4.pdf
Normal file
Binary file not shown.
BIN
docs/hw5.pdf
Normal file
BIN
docs/hw5.pdf
Normal file
Binary file not shown.
BIN
docs/hwc.pdf
Normal file
BIN
docs/hwc.pdf
Normal file
Binary file not shown.
BIN
docs/hwd.pdf
Normal file
BIN
docs/hwd.pdf
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue