Skip to content

Commit

Permalink
Merge pull request #52 from emirpasic/development
Browse files Browse the repository at this point in the history
Fix doubly linked list's element's previous pointer when inserting
  • Loading branch information
emirpasic authored Mar 5, 2017
2 parents f2025ad + e78a917 commit 51d19e7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lists/doublylinkedlist/doublylinkedlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 51d19e7

Please sign in to comment.