Apply suggestions from code review
Update DepthFirstSearch.java - signature removed, and whitespaces resolved Co-Authored-By: Libin Yang <contact@yanglibin.info>
This commit is contained in:
parent
785b570167
commit
fa1503fa77
@ -12,7 +12,6 @@ package src.main.java.com.search;
|
|||||||
* Best-case performance O(1)
|
* Best-case performance O(1)
|
||||||
* Average performance O(n)
|
* Average performance O(n)
|
||||||
*
|
*
|
||||||
* @author abir (https://github.com/abircb)
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class DepthFirstSearch {
|
public class DepthFirstSearch {
|
||||||
@ -35,14 +34,12 @@ public class DepthFirstSearch {
|
|||||||
* The BinaryTree class defines the structure of a binary tree
|
* The BinaryTree class defines the structure of a binary tree
|
||||||
* Also contains a static nested class called TreeNode
|
* Also contains a static nested class called TreeNode
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* @author abir
|
|
||||||
*/
|
*/
|
||||||
class BinaryTree<T extends Comparable<T>> {
|
class BinaryTree<T extends Comparable<T>> {
|
||||||
|
|
||||||
private TreeNode<T> root;
|
private TreeNode<T> root;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abir
|
|
||||||
* @param <P>
|
* @param <P>
|
||||||
* This class defines what a node in a binary tree looks like
|
* This class defines what a node in a binary tree looks like
|
||||||
*/
|
*/
|
||||||
@ -87,10 +84,10 @@ class BinaryTree<T extends Comparable<T>> {
|
|||||||
* @return the tree node corresponding to the key
|
* @return the tree node corresponding to the key
|
||||||
*/
|
*/
|
||||||
private TreeNode<P> find(P key) {
|
private TreeNode<P> find(P key) {
|
||||||
if(key.compareTo(this.key) == 0) return this;
|
if (key.compareTo(this.key) == 0) return this;
|
||||||
|
|
||||||
else if(key.compareTo(this.key) < 0) {
|
else if(key.compareTo(this.key) < 0) {
|
||||||
if(this.left == null) return null;
|
if (this.left == null) return null;
|
||||||
else return this.left.find(key);
|
else return this.left.find(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user