Author | Message |
---|---|
pgatsby
Posts: 10
|
Posted 22:08 Nov 23, 2018 |
I am a little confused about the delete method instructions. Since we aren't storing the data in any type of list or set. All we have are references to the next element. Are we just re-arranging the tree? I can search for the element and make it not apart of the tree, I am more confused about deleting the element itself. so for example 10 left is 4 right is 16 16 left is 13 and right is 20 if i wanted to remove 16 i will have to make 10 right reference 20 and 20 left reference 13. therefore the tree will be 10 left 4, right 20 20 left is 13 the node 16 will be "deleted" from the tree but still in memory, how would I delete that? or is this the way the method is suppose to work out. Last edited by pgatsby at
22:09 Nov 23, 2018.
|
jhurley
Posts: 207
|
Posted 08:39 Nov 24, 2018 |
Yes, this is all about changing references. In Java, you don't have to delete the node itself memory. The garbage collector will do that when it determines that there are no remaining references to the node. In some other languages, including C++, you would have to write code to free the memory. |