随笔分类 -  数据结构

摘要:### 手写数组常见方法 ```js // 数组map Array.prototype.myMap = function (callback) { const arr = [] for (let i = 0; i { return pre.concat(Array.isArray(cur) && d 阅读全文
posted @ 2023-09-05 18:42 mingL 阅读(96) 评论(0) 推荐(0)
摘要:js 有两种数据结构,array和object,es6又加了两种map和set。js实现字典看似要用object,其实应该使用数组Array,因为数组也是object 代码实现: 阅读全文
posted @ 2018-11-05 21:09 mingL 阅读(3733) 评论(0) 推荐(0)
摘要:js实现栈或者队列有两种方式: 1.数组:数组本身提供栈方法(push,pop),队列方法(push,shift)。 代码实现(栈): 代码实现(队列): 2.链表:构造链表结构,说白了就是链表的插入(尾插),移除(栈:末尾节点移除,队列:头结点移除) 代码实现(栈): 代码实现(队列): 阅读全文
posted @ 2018-11-05 00:06 mingL 阅读(1796) 评论(0) 推荐(0)
摘要:/* 定义结构 */ var node=function(element){ this.element=element this.next=null } var linkedList=function(){ this.head=new node("head") this.find=find this 阅读全文
posted @ 2018-11-04 00:47 mingL 阅读(2291) 评论(1) 推荐(0)