Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Haardiek <sven@haardiek.de>
  • Loading branch information
shaardie committed Oct 2, 2019
1 parent 938ab3b commit 6d53e55
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion double_linked_list.go
Expand Up @@ -2,6 +2,13 @@ package datastructures

import "fmt"

// DoubleLinkedList is a basic implementation of a double linked list.
//
// For more information about this data structure take a look at
// https://en.wikipedia.org/wiki/Linked_list.
//
// There are no safeguards in this implementation, if you try to read or write
// after the length is the behaviour undefined.
type DoubleLinkedList struct {
first *doubleNode
last *doubleNode
Expand Down Expand Up @@ -51,6 +58,11 @@ func (dll *DoubleLinkedList) Length() int {
return dll.length
}

// Insert a new element into the double linked list.
//
// The element is inserted on the index `index` and all elements including the
// element previously on the index `index` are moved further backwards in the
// double linked list.
func (dll *DoubleLinkedList) Insert(index int, element interface{}) {
// Panic if index is smaller 0
if index < 0 {
Expand Down Expand Up @@ -99,7 +111,7 @@ func (dll *DoubleLinkedList) Insert(index int, element interface{}) {
dll.length++
}

// NewSingleLinkedListFromList creates a new single linked list from an array.
// NewDoubleLinkedListFromList creates a new double linked list from an array.
func NewDoubleLinkedListFromList(list []interface{}) *DoubleLinkedList {
// Get length of the list
length := len(list)
Expand Down

0 comments on commit 6d53e55

Please sign in to comment.