Consider following Binary Search Tree (BST) implementation taken from some onlin
ID: 3735508 • Letter: C
Question
Consider following Binary Search Tree(BST) implementation taken from some online resource. Delete(treeNode *node, int data) deletes a node with value as data from the tree.
Understand the behavior of the function Delete(treeNode *node, int data).
Write 3 unit tests for this function. Try to cover as much of code as possible. Please, use proper assertions to verify your expected results.
Discuss if any code is missed to test after writing all 3 tests.
Notes:
You don’t need to use/run gcov to measure code coverage. Just simple discussion of coverage of the method using your unit tests will be sufficient.
You are provided few Binary Search Tree Operations at the beginning, use them to facilitate your testing. If they are not sufficient, just assume and use any Binary Search Tree operations you want to use to facilitate your test writing
typedef struct treeNode
{
int data;
struct treeNode *left;
struct treeNode *right;
}treeNode;
//BST operations
treeNode* FindMin(treeNode *node)
treeNode* FindMax(treeNode *node)
treeNode * Insert(treeNode *node,int data)
treeNode * Find(treeNode *node, int data)
treeNode * Delete(treeNode *node, int data)
{
treeNode *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = Delete(node->left, data);
}
else if(data > node->data)
{
node->right = Delete(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = Delete(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Explanation / Answer
Below is the C code for above problem with proper description provided within comments itself. Below code some sample output screenshots are attached.
If you need any other help for this Comment me below.
C code :
Sample Output :
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.