If you want to remove O (1), I think your only option is to search for the corresponding internal linked lists (with next ) and save the link.
If you use mutable.DoubleLinkedList , the situation will become a little easier:
val li = DoubleLinkedList(1,2,3,4,5,6) val elem = li.next.next.next // O(< n) until you find what you want elem.remove() // O(1) li == DoubleLinkedList(1,2,3,5,6)
But even then you wonโt have a full mirror with the mutable C ++ iterator interface.
I'm not sure if there is a valid Scala list that will support something like this. An alternative would be to use Zipper , which also provides O (1) for operations in the zipper position.
source share