Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gemini.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ java -cp classes com.williamfiset.algorithms.<package>.<ClassName>

## Development Conventions

### Documentation and Comments
- **Educational Context:** This repository is an educational project. Most comments (except for the most trivial ones) must be preserved during refactoring.
- **Purpose:** Comments should explain *how* and *why* an algorithm or data structure works to aid understanding for students and developers.
- **Refactoring:** When simplifying code, ensure that the conceptual explanations remain intact.

### Project Structure
- `src/main/java/com/williamfiset/algorithms/`: Implementation source code.
- `src/test/java/com/williamfiset/algorithms/`: Unit tests (mirrors source structure).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public boolean isEmpty() {

// Return true/false depending on whether a value exists in the tree.
public boolean contains(T value) {
if (value == null) return false;
return contains(root, value);
}

Expand Down Expand Up @@ -299,12 +300,12 @@ private T findMax(Node node) {
return node.value;
}

// Returns as iterator to traverse the tree in order.
// Returns an iterator to traverse the tree in order.
public java.util.Iterator<T> iterator() {

final int expectedNodeCount = nodeCount;
final java.util.Stack<Node> stack = new java.util.Stack<>();
stack.push(root);
final java.util.Deque<Node> stack = new java.util.ArrayDeque<>();
if (root != null) stack.push(root);

return new java.util.Iterator<T>() {
Node trav = root;
Expand Down Expand Up @@ -350,12 +351,12 @@ public String toString() {
// Make sure all left child nodes are smaller in value than their parent and
// make sure all right child nodes are greater in value than their parent.
// (Used only for testing)
public boolean validateBSTInvarient(Node node) {
public boolean validateBSTInvariant(Node node) {
if (node == null) return true;
T val = node.value;
boolean isValid = true;
if (node.left != null) isValid = isValid && node.left.value.compareTo(val) < 0;
if (node.right != null) isValid = isValid && node.right.value.compareTo(val) > 0;
return isValid && validateBSTInvarient(node.left) && validateBSTInvarient(node.right);
return isValid && validateBSTInvariant(node.left) && validateBSTInvariant(node.right);
}
}
Loading
Loading