forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 2
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
gongxun
committed
Feb 27, 2017
1 parent
dcc74d5
commit 374d7cd
Showing
14 changed files
with
764 additions
and
543 deletions.
There are no files selected for viewing
110 changes: 55 additions & 55 deletions
110
group17/785396327/binarytree/BinaryTree.java → ...785396327/2.26/binarytree/BinaryTree.java
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 |
---|---|---|
@@ -1,55 +1,55 @@ | ||
package binarytree; | ||
|
||
/** | ||
* Created by william on 2017/2/16. | ||
*/ | ||
public class BinaryTree { | ||
private Node root; | ||
|
||
class Node { | ||
private Node left; | ||
private Node right; | ||
private Comparable data; | ||
|
||
public Node(Node left, Node right, Comparable data) { | ||
this.left = left; | ||
this.right = right; | ||
this.data = data; | ||
} | ||
|
||
private void add(Comparable data) { | ||
if (this.data.compareTo(data) >= 0) | ||
if (this.left == null) | ||
this.left = new Node(null, null, data); | ||
else | ||
left.add(data); | ||
else if (this.data.compareTo(data) < 0) | ||
if (this.right == null) | ||
this.right = new Node(null, null, data); | ||
else | ||
this.right.add(data); | ||
} | ||
|
||
public Comparable getData() { | ||
return this.data; | ||
} | ||
|
||
public Node getLeft() { | ||
return this.left; | ||
} | ||
|
||
public Node getRight() { | ||
return this.right; | ||
} | ||
} | ||
|
||
public void add(Comparable data) { | ||
if (this.root == null) | ||
root = new Node(null, null, data); | ||
else this.root.add(data); | ||
} | ||
|
||
public void printByType(SearchType<Node> type) { | ||
type.printByType(this.root); | ||
} | ||
} | ||
package binarytree; | ||
|
||
/** | ||
* Created by william on 2017/2/16. | ||
*/ | ||
public class BinaryTree { | ||
private Node root; | ||
|
||
class Node { | ||
private Node left; | ||
private Node right; | ||
private Comparable data; | ||
|
||
public Node(Node left, Node right, Comparable data) { | ||
this.left = left; | ||
this.right = right; | ||
this.data = data; | ||
} | ||
|
||
private void add(Comparable data) { | ||
if (this.data.compareTo(data) >= 0) | ||
if (this.left == null) | ||
this.left = new Node(null, null, data); | ||
else | ||
left.add(data); | ||
else if (this.data.compareTo(data) < 0) | ||
if (this.right == null) | ||
this.right = new Node(null, null, data); | ||
else | ||
this.right.add(data); | ||
} | ||
|
||
public Comparable getData() { | ||
return this.data; | ||
} | ||
|
||
public Node getLeft() { | ||
return this.left; | ||
} | ||
|
||
public Node getRight() { | ||
return this.right; | ||
} | ||
} | ||
|
||
public void add(Comparable data) { | ||
if (this.root == null) | ||
root = new Node(null, null, data); | ||
else this.root.add(data); | ||
} | ||
|
||
public void printByType(SearchType<Node> type) { | ||
type.printByType(this.root); | ||
} | ||
} |
32 changes: 16 additions & 16 deletions
32
...7/785396327/binarytree/DLRSearchType.java → ...396327/2.26/binarytree/DLRSearchType.java
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
package binarytree; | ||
|
||
/** | ||
* Created by william on 2017/2/18. | ||
*/ | ||
public class DLRSearchType implements SearchType<BinaryTree.Node> { | ||
|
||
@Override | ||
public void printByType(BinaryTree.Node root) { | ||
if (root != null) { | ||
System.out.print(root.getData()+" "); | ||
printByType(root.getLeft()); | ||
printByType(root.getRight()); | ||
} | ||
} | ||
} | ||
package binarytree; | ||
|
||
/** | ||
* Created by william on 2017/2/18. | ||
*/ | ||
public class DLRSearchType implements SearchType<BinaryTree.Node> { | ||
|
||
@Override | ||
public void printByType(BinaryTree.Node root) { | ||
if (root != null) { | ||
System.out.print(root.getData()+" "); | ||
printByType(root.getLeft()); | ||
printByType(root.getRight()); | ||
} | ||
} | ||
} |
30 changes: 15 additions & 15 deletions
30
...7/785396327/binarytree/LDRSearchType.java → ...396327/2.26/binarytree/LDRSearchType.java
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
package binarytree; | ||
|
||
/** | ||
* Created by william on 2017/2/18. | ||
*/ | ||
public class LDRSearchType implements SearchType<BinaryTree.Node> { | ||
@Override | ||
public void printByType(BinaryTree.Node root) { | ||
if (root != null) { | ||
printByType(root.getLeft()); | ||
System.out.print(root.getData() + " "); | ||
printByType(root.getRight()); | ||
} | ||
} | ||
} | ||
package binarytree; | ||
|
||
/** | ||
* Created by william on 2017/2/18. | ||
*/ | ||
public class LDRSearchType implements SearchType<BinaryTree.Node> { | ||
@Override | ||
public void printByType(BinaryTree.Node root) { | ||
if (root != null) { | ||
printByType(root.getLeft()); | ||
System.out.print(root.getData() + " "); | ||
printByType(root.getRight()); | ||
} | ||
} | ||
} |
54 changes: 27 additions & 27 deletions
54
...17/785396327/binarytree/LFSearchType.java → ...5396327/2.26/binarytree/LFSearchType.java
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 |
---|---|---|
@@ -1,27 +1,27 @@ | ||
package binarytree; | ||
|
||
import java.util.LinkedList; | ||
|
||
/** | ||
* Created by william on 2017/2/18. | ||
*/ | ||
public class LFSearchType implements SearchType<BinaryTree.Node> { | ||
private LinkedList<BinaryTree.Node> queue = new LinkedList<>(); | ||
|
||
@Override | ||
public void printByType(BinaryTree.Node root) { | ||
if (root == null) | ||
return; | ||
queue.offer(root); | ||
while (!queue.isEmpty()) { | ||
BinaryTree.Node curNode = queue.poll(); | ||
System.out.print(curNode.getData() + " "); | ||
if (curNode.getLeft() != null) | ||
queue.offer(curNode.getLeft()); | ||
if (curNode.getRight() != null) | ||
queue.offer(curNode.getRight()); | ||
} | ||
|
||
} | ||
|
||
} | ||
package binarytree; | ||
|
||
import java.util.LinkedList; | ||
|
||
/** | ||
* Created by william on 2017/2/18. | ||
*/ | ||
public class LFSearchType implements SearchType<BinaryTree.Node> { | ||
private LinkedList<BinaryTree.Node> queue = new LinkedList<BinaryTree.Node>(); | ||
|
||
@Override | ||
public void printByType(BinaryTree.Node root) { | ||
if (root == null) | ||
return; | ||
queue.offer(root); | ||
while (!queue.isEmpty()) { | ||
BinaryTree.Node curNode = queue.poll(); | ||
System.out.print(curNode.getData() + " "); | ||
if (curNode.getLeft() != null) | ||
queue.offer(curNode.getLeft()); | ||
if (curNode.getRight() != null) | ||
queue.offer(curNode.getRight()); | ||
} | ||
|
||
} | ||
|
||
} |
30 changes: 15 additions & 15 deletions
30
...7/785396327/binarytree/LRDSearchType.java → ...396327/2.26/binarytree/LRDSearchType.java
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
package binarytree; | ||
|
||
/** | ||
* Created by william on 2017/2/18. | ||
*/ | ||
public class LRDSearchType implements SearchType<BinaryTree.Node> { | ||
@Override | ||
public void printByType(BinaryTree.Node root) { | ||
if (root != null) { | ||
printByType(root.getLeft()); | ||
printByType(root.getRight()); | ||
System.out.print(root.getData() + " "); | ||
} | ||
} | ||
} | ||
package binarytree; | ||
|
||
/** | ||
* Created by william on 2017/2/18. | ||
*/ | ||
public class LRDSearchType implements SearchType<BinaryTree.Node> { | ||
@Override | ||
public void printByType(BinaryTree.Node root) { | ||
if (root != null) { | ||
printByType(root.getLeft()); | ||
printByType(root.getRight()); | ||
System.out.print(root.getData() + " "); | ||
} | ||
} | ||
} |
18 changes: 9 additions & 9 deletions
18
group17/785396327/binarytree/SearchType.java → ...785396327/2.26/binarytree/SearchType.java
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
package binarytree; | ||
|
||
/** | ||
* Created by william on 2017/2/18. | ||
*/ | ||
public interface SearchType<T> { | ||
|
||
void printByType(T root); | ||
} | ||
package binarytree; | ||
|
||
/** | ||
* Created by william on 2017/2/18. | ||
*/ | ||
public interface SearchType<T> { | ||
|
||
void printByType(T root); | ||
} |
Oops, something went wrong.