扫码订阅《 Go语言算法与数据结构》或入驻星球,即可阅读文章!

GOLANG ROADMAP

阅读模式

  • 沉浸
  • 自动
  • 日常
首页
Go友会
  • 城市
  • 校园
Go学院
  • Go小课
  • Go小考
  • Go实战
  • 精品课
Go求职
  • 求职辅导🔥
  • Offer收割社群
  • 企业题库
  • 面试宝典
Go宝典
  • 在线宝典
  • B站精选
  • 推荐图书
  • 每日博文
Go仓库
实验区
  • Go周边
  • Go下载
  • Go月刊
消息
更多
  • 用户中心

    • 我的信息
    • 推广返利
  • 玩转星球

    • 星球介绍
    • 角色体系
    • 星主权益
  • 支持与服务

    • 联系星主
    • 成长记录
    • 常见问题
    • 吐槽专区
  • 合作交流

    • 渠道合作
    • 课程入驻
    • 友情链接
author-avatar

GOLANG ROADMAP


首页
Go友会
  • 城市
  • 校园
Go学院
  • Go小课
  • Go小考
  • Go实战
  • 精品课
Go求职
  • 求职辅导🔥
  • Offer收割社群
  • 企业题库
  • 面试宝典
Go宝典
  • 在线宝典
  • B站精选
  • 推荐图书
  • 每日博文
Go仓库
实验区
  • Go周边
  • Go下载
  • Go月刊
消息
更多
  • 用户中心

    • 我的信息
    • 推广返利
  • 玩转星球

    • 星球介绍
    • 角色体系
    • 星主权益
  • 支持与服务

    • 联系星主
    • 成长记录
    • 常见问题
    • 吐槽专区
  • 合作交流

    • 渠道合作
    • 课程入驻
    • 友情链接
  • 课程介绍

    • 《Go语言算法与数据结构》
  • 算法

    • 快速排序算法
    • 堆排序算法
    • 冒泡排序算法
    • 二分查找方法
    • 选择排序算法
    • 基数排序算法
    • 拓扑排序
    • 插入排序算法
    • 字符串匹配
    • 二叉搜索树
  • 数据结构

    • 图
    • 散列表
    • 堆
    • 链表
    • 跳跃表
    • 字典树

扫码订阅《 Go语言算法与数据结构》或入驻星球,即可阅读文章!

链表


GOLANG ROADMAP

# 链表分类

  • 单链表
  • 双链表
  • 环链表

# 时间复杂度

  • 修改(增删改)时间复杂度 O(1)
  • 查询时间复杂度O(n)
package linkedList

import "fmt"

type Node struct {
    Data      int
    NextPoint *Node
    PrePoint  *Node
}

type LinkedList struct {
    head    *Node
    current *Node
    tail    *Node
}

func CreatLinkedList() {
    data := []int{1, 21, 31, 51, 62, 2, 3, 42, 33, 12, 12}
    link := LinkedList{}
    var currentNode *Node
    for i := 0; i < len(data); i++ {
        currentNode = new(Node)
        currentNode.Data = data[i]
        insertNode(&link, currentNode)
    }
    showLinkedList(link)
}

func showLinkedList(link LinkedList) {
    var currentNode *Node
    currentNode = link.head
    for {
        fmt.Println("Node:", currentNode.Data)
        if currentNode.NextPoint == nil {
            break
        } else {
            currentNode = currentNode.NextPoint
        }
    }
}

func insertNode(link *LinkedList, node *Node) {
    if link.head == nil {
        link.head = node
        link.tail = node
        link.current = node
    } else {
        link.tail.NextPoint = node
        node.PrePoint = link.tail
        link.tail = node
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  • 链表分类
  • 时间复杂度