5. 链表

链表是一种物理存储单元上非连续、非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的。

package main
import "fmt"


type Node struct {
    data int
    next *Node
}

func ShowNode(p *Node)  {
	for p !=nil {
		fmt.Println(*p)
        p = p.next //移动指针
	}
}

func main() {
    var head = new(Node)
    head.data = 1
    var node1 = new(Node)
    node1.data = 2
    head.next = node1
    var node2 = new(Node)
    node2.data = 3
    node1.next = node2
    Shownode(head)
}