Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. You should implement a data structure for tree node with data field of type i

ID: 3605953 • Letter: 1

Question

1. You should implement a data structure for tree node with data field of type int; and color field of type int, taking values of either 0 (for red) or 1 (for black). It should also have the fields for parent, left, and right. You should implement a function named readRB to read in a red-black tree from the input file that is stored in pre-order format (see below for details). You should implement a function named writeRB to write out the current red-black tree to the output file, where the tree is stored in a pre-order format. You should implement a function named insertRB to insert a new node with the data field as a parameter and perform the fix-up if necessary You should implement a main function which takes the name of the input file from command prompt. The program should then read the initial tree configuration from the input file and then read the subsequent insert operations and apply them to the tree. The resulting tree should be printed in an output file by the name "output.txt". You should also prepare a Makefile which will compile your program and make sure your executable file is named "RedBlackTree". 2. 3. 4. 5.

Explanation / Answer

/*this is the answer to the first question

that is, the data structure of red black tree

some compilers will prompt warning for using typedef here. if so, please remove the keyword "typedef" from the following program

*/

struct nodeRB{

int data;

int color;//zero or one

struct nodeRB *parent;

struct nodeRB *left;

struct nodeRB *right;

};