This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| snippets:golang:containers:doublelist [2018/03/20 13:54] – allspark | snippets:golang:containers:doublelist [2018/03/20 16:52] (current) – allspark | ||
|---|---|---|---|
| Line 44: | Line 44: | ||
| list.tail = item | list.tail = item | ||
| + | } | ||
| + | |||
| + | func (list *MyList) Delete(item *MyListElement) { | ||
| + | if list.head == item && list.tail == item && item.prev == nil && item.next == nil { | ||
| + | list.head = nil | ||
| + | list.tail = nil | ||
| + | return | ||
| + | } | ||
| + | |||
| + | item.prev = item.next | ||
| + | item.next = item.prev | ||
| } | } | ||
| Line 71: | Line 82: | ||
| fmt.Println(list.Count()) | fmt.Println(list.Count()) | ||
| - | |||
| } | } | ||
| - | |||
| ``` | ``` | ||