0

what is the method for removing a node from a linked list in pseudocode?

i know how to add (im coding in java btw) but deleting has me stumped

any pointers?

4
Contributors
16
Replies
17
Views
8 Years
Discussion Span
Last Post by jbennet
0

any pointers?

I'll pardon the pun.

Do you want it for a singly linked list or a doubly linked list? I'll consider doubly linked.

Say you've got three nodes (which contain a value and left and right pointers), at locations W, X, and Y:

W={value:_; left: V; right: X}
X={value:_; left: W; right: Y}
Y={value:_; left: X; right: Z}

If you delete X, the list should look like:
W={value:_; left: V; right: Y}
X={who cares}
Y={value:_; left: W; right: Z}

Given the reference with value X, it's a simple matter of code to make stuff look like the version where X is removed. The only edge cases (maybe) are where the node you want to remove is at the beginning or end of the list. Sometimes those are edge cases, and sometimes not---it depends on your list representation.

0

Singly linked

I have nodes which are instance of classes called Node. Node has the fields Name and Price. It also has a field called Head which is a pointer to the next node.

I have the list which is an instance of the List class

The deletenode() method in List takes a value (name) and deletes it,

I just cant figure out the logic of how to do it.

0

yeah i can find it, its when i delete it, do i note what is before and after it? that way i can adjust the head pointer of the preceeding node to point to the one after the node to be deleted?

0

ah sorted it

the logic was right after all
i was using = to compare strings, not .equals, which explained why it couldnt find the node

0

we use it in class just for learning OOP and
understanding core computer science concepts (using the BlueJ environment), so it doesnt really matter whether or not its viable as an industry tool. Next semester we move to C++

0

That's what you get for using the worst programming language in popular use today :P

But thats improper use rather than the language fault. Also are you a C guy. Nowadays many Java loyals are turning to Python, they seem to be of the same opinion. I know this might seem off-topic, but we java programmers are curious about the reason.

0

i dunno i like java because its write once, run anywhere (so long as a VM exists for that platform of course) which is nice.

0

But thats improper use rather than the language fault.

No, Java is actually the worst, and it's the language's fault. It has null pointers and no closures. What other popular language his this combination?

0

i dunno i like java because its write once, run anywhere

Don't know if I'm violating any rules or something, but someone once told me:

Saying that Java is great because it runs on all operating system, is saying anal sex is great because it works on all genders

:)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.