使用go语言实现一个单链表(保存内容为int),该链表提供以下方法
1).创建链表
2).在链表头部插入一个节点
3).返回链表元素个数
4).打印链表所有的元素
type Node struct {
Data int
Next *Node
}
type List struct {
headNode *Node
}
func NewList() *List {
return &List{
headNode: &Node{},
}
}
func (this *List) Add(data int) *Node {
node := &Node{Data: data