Skip to content

Instantly share code, notes, and snippets.

@enahs
Last active August 29, 2015 14:16
Show Gist options
  • Save enahs/1d6ec40d9251a32b32d9 to your computer and use it in GitHub Desktop.
Save enahs/1d6ec40d9251a32b32d9 to your computer and use it in GitHub Desktop.

Revisions

  1. enahs renamed this gist Mar 7, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. enahs renamed this gist Mar 7, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. enahs revised this gist Mar 7, 2015. No changes.
  4. enahs created this gist Mar 7, 2015.
    34 changes: 34 additions & 0 deletions gistfile1.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    package main

    import "fmt"

    type Node struct {
    Data interface{}
    Next *Node
    }

    type list struct {
    Len int
    Head, Tail *Node
    }

    func (L *list) Push(n *Node) {
    if L.Len == 0 {
    L.Head = n
    } else {
    L.Tail.Next = n
    }
    L.Tail = n
    L.Len++
    }

    func main() {
    L := &list{}
    n1, n2, n3 := &Node{1, nil}, &Node{2, nil}, &Node{3, nil}
    L.Push(n1)
    L.Push(n2)
    L.Push(n3)
    for curr := L.Head; curr != nil; curr = curr.Next {
    fmt.Printf("%#v", curr.Data)
    }
    }