随笔分类 - 数据结构与算法
摘要:栈 /** * 栈 */ class stack { constructor() { this.count = 0 this.items = {} } /** * 添加到栈顶 */ push(element) { this.items[this.count] = element this.count
阅读全文
摘要:双端队列 /** * 双端队列 */ class Deque { constructor() { // 队列当前索引 this.count = 0 // 队头索引 this.lowestCount = 0 // 存储队列 this.items = {} } /** * 添加到队头 */ addFro
阅读全文
摘要:队列 /** * 创建队列 */ class Queue { constructor() { // 队列当前索引 this.count = 0 // 队头索引 this.lowestCount = 0 // 存储队列 this.items = {} } /** * 入队 */ enqueue(ele
阅读全文
摘要:字典是什么? 与set类似,map也是一种存储唯一值得数据结构,但它是以键值对的形式来存储 常用操作:键值对的增删改查 求两个数组的交集 给定两个数组,编写一个函数来计算它们的交集 let intersection = function (nums1, nums2) { const map = ne
阅读全文
摘要:集合是什么? 一种 无序且唯一 的数据结构 ES6中有集合,名为Set 集合的常用操作:数组去重,判断某元素是否在集合中,求交集 // 去重 const arr = [1, 1, 2, 2] const set = new Set(arr) // { 1, 2 } const arr2 = [...
阅读全文