mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 14:34:05 +08:00
Remove unnecessary code (#4141)
This commit is contained in:
@ -49,8 +49,7 @@ public class AVLSimple {
|
||||
|
||||
private Node insert(Node node, int item) {
|
||||
if (node == null) {
|
||||
Node add = new Node(item);
|
||||
return add;
|
||||
return new Node(item);
|
||||
}
|
||||
if (node.data > item) {
|
||||
node.left = insert(node.left, item);
|
||||
|
@ -62,21 +62,20 @@ public class AVLTree {
|
||||
}
|
||||
return;
|
||||
}
|
||||
Node child;
|
||||
if (node.left != null) {
|
||||
Node child = node.left;
|
||||
child = node.left;
|
||||
while (child.right != null) {
|
||||
child = child.right;
|
||||
}
|
||||
node.key = child.key;
|
||||
delete(child);
|
||||
} else {
|
||||
Node child = node.right;
|
||||
child = node.right;
|
||||
while (child.left != null) {
|
||||
child = child.left;
|
||||
}
|
||||
node.key = child.key;
|
||||
delete(child);
|
||||
}
|
||||
node.key = child.key;
|
||||
delete(child);
|
||||
}
|
||||
|
||||
public void delete(int delKey) {
|
||||
@ -216,11 +215,7 @@ public class AVLTree {
|
||||
|
||||
public boolean search(int key) {
|
||||
Node result = searchHelper(this.root, key);
|
||||
if (result != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return result != null;
|
||||
}
|
||||
|
||||
private Node searchHelper(Node root, int key) {
|
||||
|
@ -117,11 +117,9 @@ public class BinaryTree {
|
||||
if (value < parent.data) {
|
||||
parent.left = newNode;
|
||||
parent.left.parent = parent;
|
||||
return;
|
||||
} else {
|
||||
parent.right = newNode;
|
||||
parent.right.parent = parent;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -177,7 +175,6 @@ public class BinaryTree {
|
||||
if (temp == root) {
|
||||
successor.parent = null;
|
||||
root = successor;
|
||||
return true;
|
||||
} // If you're not deleting the root
|
||||
else {
|
||||
successor.parent = temp.parent;
|
||||
@ -188,8 +185,8 @@ public class BinaryTree {
|
||||
} else {
|
||||
temp.parent.left = successor;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
} // One child
|
||||
else {
|
||||
// If it has a right child
|
||||
@ -207,7 +204,6 @@ public class BinaryTree {
|
||||
} else {
|
||||
temp.parent.right = temp.right;
|
||||
}
|
||||
return true;
|
||||
} // If it has a left child
|
||||
else {
|
||||
if (temp == root) {
|
||||
@ -223,8 +219,8 @@ public class BinaryTree {
|
||||
} else {
|
||||
temp.parent.right = temp.left;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,6 @@ public class GenericTree {
|
||||
for (int i = 0; i < node.child.size(); i++) {
|
||||
depth(node.child.get(i), dep - 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -309,23 +309,20 @@ public class RedBlackBST {
|
||||
|
||||
public void insertDemo() {
|
||||
Scanner scan = new Scanner(System.in);
|
||||
while (true) {
|
||||
System.out.println("Add items");
|
||||
System.out.println("Add items");
|
||||
|
||||
int item;
|
||||
Node node;
|
||||
int item;
|
||||
Node node;
|
||||
|
||||
item = scan.nextInt();
|
||||
while (item != -999) {
|
||||
node = new Node(item);
|
||||
insert(node);
|
||||
item = scan.nextInt();
|
||||
while (item != -999) {
|
||||
node = new Node(item);
|
||||
insert(node);
|
||||
item = scan.nextInt();
|
||||
}
|
||||
printTree(root);
|
||||
System.out.println("Pre order");
|
||||
printTreepre(root);
|
||||
break;
|
||||
}
|
||||
printTree(root);
|
||||
System.out.println("Pre order");
|
||||
printTreepre(root);
|
||||
scan.close();
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ public class TrieImp {
|
||||
}
|
||||
currentNode = node;
|
||||
}
|
||||
if (currentNode.end == true) {
|
||||
if (currentNode.end) {
|
||||
currentNode.end = false;
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user