Home > database >  How to simulate a pointer to LinkedList element in Java?
How to simulate a pointer to LinkedList element in Java?

Time:10-12

I need an object, that

  • points to element of linked list

  • can be iterated to next

  • can be cloned

  • all operations should be O(1)

I don't see proofs, that ListIterator complies these requirements. Particularly, I don't see it is Cloneable.

CodePudding user response:

There is no class that fulfill all the criteria for java.util.LinkedList. You need to implement your own linked list for that.

CodePudding user response:

java.util.LinkedList and it's iterators have limitations. Assigning an iterator only creates another reference to the same iterator object, so not "cloneable" assuming that's what you mean by "cloneable". If you create multiple iterators to a list, if any nodes are added or removed from a list, all iterators (except one used for add) will be invalidated. There's no equivalent of C std::list::splice(), which can move one or mode nodes within a list or from list to list.

  • Related