Sfoglia il codice sorgente

Merge pull request #1025 from jackattack24/simplify-bst

binary-search-tree: simplify reference implementation
FridaTveit 8 anni fa
parent
commit
70b21350a4
No account linked to committer's email

+ 8
- 8
exercises/binary-search-tree/.meta/src/reference/java/BinarySearchTree.java Vedi File

@@ -9,20 +9,20 @@ class BinarySearchTree<T extends Comparable<T>> {
9 9
         if (root == null) {
10 10
             root = new Node<>(value);
11 11
         } else {
12
-            this.insert(this.root, value);
12
+            insert(root, value);
13 13
         }
14
-        this.nodeCount++;
14
+        nodeCount++;
15 15
     }
16 16
 
17 17
     List<T> getAsSortedList() {
18
-        List<T> result = new ArrayList<>(this.nodeCount);
19
-        this.putInSortedOrderToList(this.root, result);
18
+        List<T> result = new ArrayList<>(nodeCount);
19
+        putInSortedOrderToList(root, result);
20 20
         return Collections.unmodifiableList(result);
21 21
     }
22 22
 
23 23
     List<T> getAsLevelOrderList() {
24
-        List<T> result = new ArrayList<>(this.nodeCount);
25
-        this.putInLevelOrderToList(this.root, result);
24
+        List<T> result = new ArrayList<>(nodeCount);
25
+        putInLevelOrderToList(root, result);
26 26
         return Collections.unmodifiableList(result);
27 27
     }
28 28
 
@@ -33,13 +33,13 @@ class BinarySearchTree<T extends Comparable<T>> {
33 33
     private void insert(Node<T> node, T value) {
34 34
         if (value.compareTo(node.getData()) <= 0) {
35 35
             if (node.getLeft() == null) {
36
-                node.setLeft(new Node<T>(value));
36
+                node.setLeft(new Node<>(value));
37 37
             } else {
38 38
                 insert(node.getLeft(), value);
39 39
             }
40 40
         } else {
41 41
             if (node.getRight() == null) {
42
-                node.setRight(new Node<T>(value));
42
+                node.setRight(new Node<>(value));
43 43
             } else {
44 44
                 insert(node.getRight(), value);
45 45
             }