From 8f2043f5e665185be96e55cfe0acada9c90f3bcc Mon Sep 17 00:00:00 2001 From: noah Date: Wed, 20 Apr 2022 22:13:48 -0500 Subject: [PATCH] Insert, delete, cleanup --- Schrick-Noah_Project-Writeup.tex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Schrick-Noah_Project-Writeup.tex b/Schrick-Noah_Project-Writeup.tex index ffceccb..5a2045b 100644 --- a/Schrick-Noah_Project-Writeup.tex +++ b/Schrick-Noah_Project-Writeup.tex @@ -54,12 +54,16 @@ To minimize programmer error and to alleviate effort, an enum titled ``colors" w 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} +A red-black tree class was created to aid in the red-black tree functionality. It does not contain any data members other than a pointer to root node. This class primarily works to implement auxiliary functions needed to manage the tree, such as inserts, deletions, rotations, and re-colorings. \subsubsection{Insert} +The insert function takes two arguments, both of which are pointers to nodes. The first argument is to aid in the recursion process, and begins as the pointer to the root node. The second argument is the pointer to the node that will be inserted. For the location of insertion, a recursion process is followed, where the key of the node to be inserted is compared to a current node. The tree is then traversed via recursion based on if the key is greater than or less than the current node. Respectively, the right child or left child of the current node is then passed. After the location is determined and the node is inserted, the cleanup function is called. \subsubsection{Delete} +The delete function takes two arguments. The first is a pointer to a node, and similar to the insert process, this pointer is used to aid in a recursion process. The second argument is an integer that corresponds to the key of the node to delete. The recursion process is identical to that of the insertion process, with an additional check to see if the key is equal to the key of the current node. If the keys are equal, the deletion process is performed. For the deletion process itself, the approach taken was the successor method as discussed during lecture. The cleanup function was called after the node deletion was completed. -\subsubsection{Tree Cleanup} \label{sec:print} +\subsubsection{Tree Cleanup} +The cleanup function was implemented by following the pseudocode of the three cases discussed during lecture, and the function takes a sole argument, which is a pointer to the node currently being examined. The function makes use of a while loop that checks if the current node and its parent are both red. Each case respectively calls the left and right rotate as necessary. \subsubsection{Display}