首页 > 其他 > 详细

golang构造单链表

时间:2018-11-10 18:40:25      阅读:167      评论:0      收藏:0      [点我收藏+]
原文地址: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
}

 

golang构造单链表

原文:https://www.cnblogs.com/zhouqi666/p/9940026.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!