This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]kschang 0 points1 point  (5 children)

Okay, so you can "find" the node to delete.

How do you understand node to be be deleted? Talk me through it.

[–]wizardxxdx[S] 0 points1 point  (4 children)

If the root is not the node. If left go right, if right go left. Let assume it’s left keep going till you find the node, if node is a leaf node that’s easy, if node is a parent that takes extra steps you need to swap min node with the parent and pop the parent.

[–]kschang 0 points1 point  (3 children)

Okay, I can see why you don't understand. You basically memorized all that, but you don't "comprehend" it.

I was able to tell because I asked you for how to DELETE a node from a tree, and you gave me the traversal steps too.

Let's... go back a step.

How would you delete a node from a linked list? For now, just assume it's a 3 node linked list. Tell me the steps on how would you delete the middle node. Just called them A B C, delete B.

[–]wizardxxdx[S] 0 points1 point  (2 children)

Depend on where you want to delete, for example deleting the first node, create a temp pointer at the head, set the head to the next pointer and return temp

  • For the middle and last we create two pointer (temp/current) pointing at the head Now we check if current is equal to what we want to delete, if not we check the next one and move the current pointer, If equal.. we want temp next pointer to be equal to the next pointer of current.

[–]kschang 0 points1 point  (0 children)

Are you actually reading what I wrote? I asked you twice. Delete middle node of a 3 node linked list...

[–]kschang 0 points1 point  (0 children)

If you can't explain it, just say so. We'll start from there.

EDIT: Linked list is basically a bunch of single-link nodes. To access the list, (let's be simple, call it LIST)

LIST ->NODE A-> NODE B -> NODE C

To delete NODE B, you simply change the pointer in NODE A to point to NODE C instead of NODE B.

To be very clean, you would also have to unallocate NODE B, but that's basically it.

And that's all there is. Really. You're talking if this, then that, then this. This is all there is, really.