diff options
Diffstat (limited to 'go')
-rw-r--r-- | go/linkedlist.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/go/linkedlist.go b/go/linkedlist.go index 31aa77c..b41b168 100644 --- a/go/linkedlist.go +++ b/go/linkedlist.go @@ -32,12 +32,22 @@ func (head *node) pushTail(val int) { head.next = nil } +func (head *node) pushHead(val int) { + cpnode := &node{ + v: head.v, + next: head.next, + } + head.v = val + head.next = cpnode +} + func main() { lista := new(node) lista.next = nil lista.load(5) lista.pushTail(32) + lista.pushHead(24) for lista != nil { fmt.Printf("%d ",lista.v) lista = lista.next |