package main
import"fmt"// MyListElement contains custom-attributes and internal datatype MyListElement struct{
Name string
Age int
next *MyListElement
prev *MyListElement
}// Next iterates to the next list element, or nil if end of listfunc(i*MyListElement) Next()*MyListElement {returni.next
}// MyList structure, pointer for begin and end elementtype MyList struct{
head *MyListElement
tail *MyListElement
}// Append item to end of listfunc(list *MyList) Append(item *MyListElement){if list.head ==nil && list.tail ==nil{
list.head = item
list.tail = item
item.next =nil
item.prev =nilreturn}
list.tail.next = item
item.prev = list.tail
item.next =nil
list.tail = item
}// Count elements in listfunc(list *MyList) Count()int{
count :=0fori:= list.head;i!=nil;i=i.next {
count++}return count
}func main(){
list := MyList{}{
a := &MyListElement{Name:"Max", Age:23}
list.Append(a)}{
b := &MyListElement{Name:"Hans", Age:42}
list.Append(b)}
fmt.Println(list.Count())}
snippets/golang/containers/doublelist.1521550461.txt.gz · Last modified: by allspark