Again, this is similar to what should be obvious.
I would like to insert an item into a linked list at a specific position.
In one case, this field in an element is less than a certain value, so I can do it as follows:
def Add(act:Elem):Unit = {
val (before, after) = myList.partition(elem.n >= _.n)
myList = (before :+ act) ++ after
}
... but this is truly an immutable approach, disguised as volatile. I donβt think I can get a LinkedList node that matches the insertion point, so I cannot mess with the following attribute.
It should not be so difficult. Half of the linked list items are that you insert things in the middle.
I was still messing with the compiler generator (as in this question ). Replacing lists with copies is simply not the way to do this, since there are many recursive calls during which the lists are quite deliberately modified, so you may find that some of the recursive calls still use the list that you just replaced.
I really need volatile lists and simple mutable operations. I think I can write my own collection classes, but I don't think this is unusual. Has anyone already implemented the "correct" multiply-linked lists?
EDIT
Additional Information
. , , , ( , )
Java, , next ( ).
Scala LinkedList node , , , LinkedList node , , .
, .
DoublyLinkedList , , , , . , , . . Java/ . Scala DoublyLinkedList node -, . node, .
: -, Trait, ( ). , . , , , (, , "" , "nezt", "" "" ).
, , , (.. ).