Question

When debugging a crashing program for manipulating Projects, where each project contains a linked list of...

  1. 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

  2. Given the declaration:

    struct TreeNode {
        int data;
        TreeNode* left;
        TreeNode* right;
    };

    Write a function to compute the height of a binary tree:

    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.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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);
}
}

Add a comment
Know the answer?
Add Answer to:
When debugging a crashing program for manipulating Projects, where each project contains a linked list of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Part 1: Implement a singly linked list -------------------------------------- (a) Your job is to implement a generic...

    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 *))...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT