Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bsTree.c- Do we really need the function to destroy single node? #195

Open
louis10229 opened this issue Apr 12, 2019 · 2 comments
Open

bsTree.c- Do we really need the function to destroy single node? #195

louis10229 opened this issue Apr 12, 2019 · 2 comments
Labels
TreeMap Use for issues about treemap

Comments

@louis10229
Copy link

I don't think that we need to worry about destroy just single node since we can destroy the whole tree at once just like the code I wrote in lab9.

@louis10229 louis10229 added the TreeMap Use for issues about treemap label Apr 12, 2019
@CaptainNeemo
Copy link

I think we might need it because when we want to finally print what we have, when we find the maximum count in a node we print it and then we delete the node, then we run the find max function again to find the next max.

We can't not delete the node, because if we do then we have a problem:
Imagine we have 3 words with count 3, when we find the first and print it, we will run the program again, we will find the same node again.. and we might not find the third node with count 3 at all.

So yea I think we need it.

@powderflask
Copy link
Contributor

I think you are talking about distinct issues. Louis is asking: do we need a function to destroy one node, and the answer to that is: IF the node contains dynamic memory (e.g. if its constructor function allocates more memory than just the Node struct), then you DEFINITELY need a function to destroy the node, and thus free any dynamic memory it is managing. Destroying the tree will free dynamic nodes in the tree, but not memory allocated within the node.

Nima is talking about the algorithm to extract the count data from the tree. This will use the tree's API to remove nodes from the tree (for reasons Nima gives above), but it is not concerned with any of the internal details of how the tree accomplishes this.

So long as there is a Remove Node function, Nima will be happy.
So long as removing a node does not create a memory leak, Joseph will be happy :-)

louis10229 pushed a commit that referenced this issue Apr 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TreeMap Use for issues about treemap
Projects
None yet
Development

No branches or pull requests

3 participants