Полагаю, вам нужна глубокая копия вашего двусвязного списка.
Doubly iterator = this.getFirstChild();
Doubly newList = iterator.copyNode();
Doubly newListTail = newList;
Doubly deepCurrNode = null
while ((iterator = iterator.getNext()) != null)
{
deepCurrNode = iterator.copyNode();
newListTail.setNext(deepCurrNode);
deepCurrNode.setPrevious(newListTail);
newListTail = deepCurrNode;
}
//just in case these aren't already null, I'll be explicit
newList.setPrevious(null);
newListTail.setNext(null);
return newList;
EDIT:
Объяснение
код псевдо выглядит следующим образом:
while (more items, set iterator equal to next node)
{
deepCurrNode <-- get deep copy of iterator (this is the item i want to add to my newList)
Set the tail's next to deepCurrNode to link them
Set deepCurrNode's previous to the tail to link backwards
Set the Tail to point to the new tail of the list (deepCurrNode)
}