mirror of
https://github.com/emirpasic/gods
synced 2024-11-06 15:20:25 +00:00
Merge pull request #52 from emirpasic/development
Fix doubly linked list's element's previous pointer when inserting
This commit is contained in:
commit
51d19e739f
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user