Skip to content

RB Trees #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dataStructures.queue;
package dataStructures.queue.monotonicQueue;


import java.util.ArrayDeque;
Expand Down
149 changes: 149 additions & 0 deletions src/main/java/dataStructures/rbTree/RBNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package dataStructures.rbTree;

/**
* This class represents a node for the Red-Black Tree.
*
* @param <T> The type of element being stored in the node.
*/
public class RBNode<T extends Comparable<T>> {

enum VAL {
RED,
BLACK
}

/**
* The element held by the node.
*/
private T element;

/**
* The color the node is marked with.
*/
private VAL color;


/**
* The left child node.
*/
private RBNode<T> left;

/**
* The right child node.
*/
private RBNode<T> right;

/**
* The parent node.
*/
private RBNode<T> parent;

/**
* Constructor for our RB-Tree node.
* Defaults to red.
*
* @param element The element to add.
* @param left The left child node.
* @param right The right child node.
*/
public RBNode(T element, RBNode<T> left, RBNode<T> right) {
this.element = element;
this.left = left;
this.right = right;
this.color = VAL.RED;
this.parent = null;
}

/**
* Constructor for a NIL node.
*/
public RBNode() {
this.element = null;
this.parent = null;
this.left = null;
this.right = null;
this.color = VAL.BLACK;
}

/**
* Sets right node.
*
* @param other The new right node.
*/
public void setRight(RBNode<T> other) {
this.right = other;
}

/**
* Sets left node.
*
* @param other The new left node.
*/
public void setLeft(RBNode<T> other) {
this.left = other;
}

/**
* Sets parent node.
*
* @param other The new parent node.
*/
public void setParent(RBNode<T> other) {
this.parent = other;
}

/**
* Getter for element
*
* @return The element in the node.
*/
public T getElement() {
return this.element;
}

/**
* Getter for parent node.
*
* @return The parent node.
*/
public RBNode<T> getParent() {
return this.parent;
}

/**
* Getter for right child node.
*
* @return The right child node.
*/
public RBNode<T> getRight() {
return this.right;
}

/**
* Getter for left child node.
*
* @return The left child node.
*/
public RBNode<T> getLeft() {
return this.left;
}

/**
* Getter for node color.
*
* @return The color the node is marked in.
*/
public VAL getColor() {
return this.color;
}

/**
* Changes the color of the node.
*
* @param color The color to change to.
*/
public void setColor(VAL color) {
this.color = color;
}

}
Loading