summaryrefslogtreecommitdiff
path: root/go
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-08-06 17:29:23 +0200
committerSanto Cariotti <sancn@live.com>2017-08-06 17:29:23 +0200
commit26c5b163994229424f2873f54fafac845759f371 (patch)
tree9c320bbb670c9399ba76e1760b0153bb1cbbed54 /go
parent9b354ee72bad2adc5f09caa80358859cbe5c2618 (diff)
push on head
Diffstat (limited to 'go')
-rw-r--r--go/linkedlist.go10
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