From 26c5b163994229424f2873f54fafac845759f371 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sun, 6 Aug 2017 17:29:23 +0200 Subject: push on head --- go/linkedlist.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'go') 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 -- cgit v1.2.3-18-g5258