Node Class

This commit is contained in:
Noah L. Schrick 2022-04-20 19:53:46 -05:00
parent dbc20ce287
commit 99a5f6ade9

View File

@ -47,15 +47,21 @@ This program offers no guarantee of functionality on other Operating Systems. Te
\section{Programming Approach}
\subsection{Node Class}
This work approached the problem with a traditional method when working with tree structures by using a series of connected nodes. To achieve this, a ``Node" class was implemented. The Node class contains 5 private members: a pointer to the parent node, a pointer to the left child, a pointer to the right child, an integer key, and an integer color. Public class functions include auxiliary functions to get and set the pointers for the parent and children nodes, get and set the color value, and get the key. The Node class is constructed with an integer key value, the color is initialized to red, and the parent and children node pointers are initialized to null pointers using C++'s ``nullptr" keyword.
To minimize programmer error and to alleviate effort, an enum titled ``colors" was created, with black being set to 0, and red set to 1. Likewise, a color name character array was created, with ``black" in the first position, and red in the second. When getting and setting colors, rather than needing to remember (or look for) the value of red or black, the programmer can simply pass ``red" or ``black", which will then be converted to its proper integer value. Since Red-Black trees use bits to represent the color, this approach was preferred over the utilization of a string member for color.
For debugging purposes, a print function was also created. This function will print the key, color, parent key, left child key, and right child key of a given node.
\subsection{Red-Black Tree Class}
\subsubsection{Constructing the Problem}
\subsubsection{Insert}
\subsubsection{Generating the Solution}
\subsubsection{Delete}
\subsubsection{Printing the solution} \label{sec:print}
\subsubsection{Tree Cleanup} \label{sec:print}
\subsubsection{Display}
\section{Results}
\subsection{Part 1.B: ``Tree 1"}