When debugging a crashing program for manipulating Projects,
where each project contains a linked list of Staff records, you
discover that two different projects have pointers to the same
linked list node.
Likely causes for this problem might be:
Failure to provide explicit forms of the Big 3 |
||
An undefined static variable |
||
Inappropriate use of shallow copy |
||
A memory leak due to an improper destructor |
||
Failure to provide a default constructor |
struct TreeNode {
int data;
TreeNode* left;
TreeNode* right;
};
int height(TreeNode *root)
On this, and on any subsequent questions where you are asked to give code, please use the Formatted paragraph style rather than Normal.Answer 1:
Inappropriate use of shallow copy |
when we dont use the shallow copy properly reference will point to the same memory locations
Answer 2:
int height(TreeNode * root)
{
if (root == NULL)
return 0;
else
{
/* get height of each subtree */
int leftH= height(root->left);
int rightH = height(root->right);
if (leftH > rightH)
return(leftH + 1);
else return(rightH + 1);
}
}
When debugging a crashing program for manipulating Projects, where each project contains a linked list of...
Part 1: Implement a singly linked list -------------------------------------- (a) Your job is to implement a generic singly linked list that can hold any data type. The interface has been specified and provided to you in a header file called mylist.h. So your job is to write mylist.c that implements each function whose prototype is included in mylist.h. Specifically, you are asked to write the following functions: struct Node *addFront(struct List *list, void *data) void traverseList(struct List *list, void (*f)(void *))...