Does Java 1.5 have circular linkedlist implementation?

S

Sharp

Hi
Does Java 1.5 have circular linkedlist implementation?
if not, where can I find a 3rd party API that has it?

Cheers
Sharp
 
T

Tony Morris

Sharp said:
Hi
Does Java 1.5 have circular linkedlist implementation?
if not, where can I find a 3rd party API that has it?

Cheers
Sharp

No.
Google could turn one up, but I see no reason to spend the 5 or 10 minutes
writing it yourself instead (perhaps a tad more if you write tests and
javadoc, like you should).
Note that a circular linked list cannot be implemented successfully (without
design flaws) by implementing the java.util.List interface -I've seen many
of my university students try.
 
K

Kevin McMurtrie

Tony Morris said:
No.
Google could turn one up, but I see no reason to spend the 5 or 10 minutes
writing it yourself instead (perhaps a tad more if you write tests and
javadoc, like you should).
Note that a circular linked list cannot be implemented successfully (without
design flaws) by implementing the java.util.List interface -I've seen many
of my university students try.

I don't see why it can't implement List if given a reference point and
direction. It couldn't cleanly support concurrent modification through
itself and an Iterator but that's a common limitation.
 
T

Thomas G. Marshall

Kevin McMurtrie coughed up:
I don't see why it can't implement List if given a reference point and
direction.

I've seen this discussion a few times. You can specify a reference point,
but that reference point is hard to pin down in a generic sense. What
constitutes the head, or better put, "the way in" to a circular linked list
is often goofy.

It couldn't cleanly support concurrent modification
through itself and an Iterator but that's a common limitation.


You could specify a ListIterator, which is what you get from List
implementors anyway. And a ListIterator has the add() and remove() methods
needed for such concurrent things. Once you've chosen that arbitrary head
and tail in the circle, the ListIterator could be designed in a similar way
it is for ArrayList.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top