接口链表
package main
type LinkNode struct{
data interface()
next *LinkNode
}
type Link struct{
head *LinkNode
}
func (p *Link) InertHead(data interface{}){
node := &Link{
data:data
next:nil
}
if (p.tail == nil && p.head == nil){
p.tail = node
p.head = node
return
}
node.next = p.head
p.head = node
}
func (p *Link) InertTail(data interface{}){
node := &LinkNode{
data:data
next:nil
}
if (p.tail == nil && p.head == nil){
p.tail = node
p.head = node
return
}
p.tail.next = node
p.tail = node
}
func (p *Link) Trans(){
q := p.head
for q != nil{
fmt.Println(q.data)
q = q.next
}
}
func main(){
var link Link
for i := 0; i < 10; i++ {
link.InsertHead(i)
}
link.Trans()
}