golang构造单链表

原文地址:http://www.niu12.com/article/47
package main import "fmt" type ListNode struct {
Value int
Next *ListNode
} func main() {
one := makeListNode([]int{1, 2, 3})
for one != nil {
fmt.Println(one.Value)
one = one.Next
}
} func makeListNode(nums []int) *ListNode { if len(nums) == 0{
return nil
} res := &ListNode{
Value:nums[0],
} temp := res for i := 1; i < len(nums); i++ {
temp.Next = &ListNode{Value:nums[i],}
temp = temp.Next
} return res
}
上一篇:利用Node.js实现模拟Session验证的登陆


下一篇:HP-UX平台安装Oracle11gR2数据库