documentation on doubly linked list

pull/1/head
Emir Pasic 9 years ago
parent af024c9a3e
commit e112848ae9

@ -12,6 +12,7 @@ Implementation of various data structures in Go.
- [TreeSet](#treeset)
- [Lists](#lists)
- [ArrayList](#arraylist)
- [DoublyLinkedList](#doublylinkedlist)
- [Stacks](#stacks)
- [LinkedListStack](#linkedliststack)
- [ArrayStack](#arraystack)
@ -182,6 +183,44 @@ func main() {
}
```
#####DoublyLinkedList
This structure implements the _List_ interface and is a linked data structure where each element points to the next and previous element in the list.
Direct access method _Get(index)_ and _Remove()_ are of linear performance. _Append_ and _Prepend_ are of constant time performance. Checking with _Contains()_ is of quadratic complexity.
```go
package main
import (
dll "github.com/emirpasic/gods/lists/doublylinkedlist"
"github.com/emirpasic/gods/utils"
)
func main() {
list := dll.New()
list.Add("a") // ["a"]
list.Append("b") // ["a","b"] (same as Add())
list.Prepend("c") // ["c","a","b"]
list.Sort(utils.StringComparator) // ["a","b","c"]
_, _ = list.Get(0) // "a",true
_, _ = list.Get(100) // nil,false
_ = list.Contains("a", "b", "c") // true
_ = list.Contains("a", "b", "c", "d") // false
list.Remove(2) // ["a","b"]
list.Remove(1) // ["a"]
list.Remove(0) // []
list.Remove(0) // [] (ignored)
_ = list.Empty() // true
_ = list.Size() // 0
list.Add("a") // ["a"]
list.Clear() // []
}
```
####Stacks
The stack interface represents a last-in-first-out (LIFO) collection of objects. The usual push and pop operations are provided, as well as a method to peek at the top item on the stack, a method to check whether the stack is empty and the size (number of elements).

Loading…
Cancel
Save