Merge pull request #52 from emirpasic/development

Fix doubly linked list's element's previous pointer when inserting
This commit is contained in:
Emir Pasic 2017-03-05 23:34:24 +01:00 committed by GitHub
commit 51d19e739f

View File

@ -259,18 +259,22 @@ func (list *List) Insert(index int, values ...interface{}) {
if i == 0 {
list.first = newElement
} else {
newElement.prev = beforeElement
beforeElement.next = newElement
}
beforeElement = newElement
}
oldNextElement.prev = beforeElement
beforeElement.next = oldNextElement
} else {
oldNextElement := beforeElement.next
for _, value := range values {
newElement := &element{value: value}
newElement.prev = beforeElement
beforeElement.next = newElement
beforeElement = newElement
}
oldNextElement.prev = beforeElement
beforeElement.next = oldNextElement
}
}