数据结构 #
常用的数据结构 #
数据结构定义(源码) #
栈 #
stack := make([]int, 0)
// push 入栈
stack = append(stack, 3)
// pop 出栈
v := stack[len(stack) - 1]
stack = stack[: len(stack) - 1]
// 判断栈为空
if len(stack) == 0 {
}
队列 #
queue := make([]int, 0)
// enqueue 入队
queue = append(queue, 5)
// dequeue 出队
v := queue[0]
queue = queue[1:]
// 判断长度为 0
if len(queue) == 0 {
}
链表 (Linked List) #
单向链表 节点 #
# Definition for singly-linked list.
class ListNode(object):
def __init__(self, val):
self.val = val
self.next = None
# Definition for singly-linked list.
class ListNode:
def __init__(self, val):
self.val = val
self.next = None
双向链表 节点 #
# Definition for doubly-linked list.
class ListNode(object):
def __init__(self, val):
self.val = val
self.pre = None
self.next = None
# Definition for doubly-linked list.
class ListNode:
def __init__(self, val):
self.val = val
self.pre = None
self.next = None
树 #
# Definition for a binary tree node
class TreeNode(object) {
def __init__(self, val):
self.val = val
self.left = None
self.right = None
}
# Definition for a binary tree node
class TreeNode {
def __init__(self, val):
self.val = val
self.left = None
self.right = None
}
数据结构列表 #
类型 #
抽象类型 #
数组 #
- 字符串
- 位数组(英语:Bit array)
- 环形缓冲器
- 动态数组(英语:Dynamic array)
- 哈希表
- 哈希数组树(英语:Hashed array tree)
- 稀疏矩阵
链 #
- 关联表(英语:Association list)
- 链表
- 跳跃列表
- 松散链表(英语:Unrolled linked list)
- 异或链表
叶王 © 2013-2024 版权所有。如果本文档对你有所帮助,可以请作者喝饮料。