
算法
huxianc
这个作者很懒,什么都没留下…
展开
-
js 实现排序
function ArrayList() { this.array = []; ArrayList.prototype.insert = function (item) { this.array.push(item); }; // 交换位置 ArrayList.prototype.swap = function (m, n) { const temp = this.array[m]; this.array[m] = this.array[n]; th.原创 2021-04-19 16:41:50 · 113 阅读 · 0 评论 -
js 实现字典、图
字典 function Dictionary() { this.items = {}; Dictionary.prototype.set = function (key, value) { this.items[key] = value; }; Dictionary.prototype.has = function (key) { return this.items.hasOwnProperty(key); }; Dictionary.prototype.rem原创 2021-04-19 15:14:30 · 148 阅读 · 0 评论 -
js实现二叉搜索树
function BinarySearchTree() { function Node(key) { this.key = key; this.left = null; this.right = null; } this.root = null; BinarySearchTree.prototype.insert = function (key) { const newNode = new Node(key); if (this.root ===原创 2021-04-18 19:48:30 · 172 阅读 · 0 评论 -
js实现集合
function Set() { this.items = {}; Set.prototype.add = function (value) { if (this.has(value)) return false; this.items[value] = value; return true; }; Set.prototype.has = function (value) { return this.items.hasOwnProperty(value);原创 2021-04-15 16:58:19 · 181 阅读 · 0 评论