
js数据结构与算法
算法与数据结构
踏着阳光
这个作者很懒,什么都没留下…
展开
-
snowflake算法解决分布式ID自动生成
nodejs版本实现https://www.npmjs.com/package/node-snowflake#see-examplesexamplejs//only run simple http serverrequire('node-snowflake').Server(3001);//request url example:GET http://localhost:3001/next_id?worker_id={optional}&data_center_id={option.转载 2020-08-27 01:13:11 · 2219 阅读 · 0 评论 -
js 字典与Map对象
字典是一种以键-值对形式存储数据的数据结构,像电话簿里面的电话和号码一样,本文字典的的基础类为Array.字典实现:function Dictionary() { this.datastore = []; this.add = add; this.find = find; this.remove = remove; this.showAll =...原创 2019-04-22 18:39:14 · 9716 阅读 · 0 评论 -
js 集合
并集:将两个集合中的成员进行合并,得到一个新的集合交集:两个集合共同存在的成员组成一个新的集合补集:属于一个集合而不属于另一个集合的成员组成的集合function Set() { this.dataStore = []; this.add = add; this.remove = remove; this.show = show; this.c...原创 2019-04-11 17:27:31 · 4517 阅读 · 0 评论 -
js 插入排序
插入排序有两个循环,外循环数组元素挨个移动,而内循环和外循环选中的元素进行比较。如果外循环中选中的元素比内循环选中的元素要小,那么数组整体会向右移动,为内循环的这个元素腾出位置。(将较大数组向右移动,为数组较小元素腾出位置。)function CArray(numElements) { this.dataStore = []; this.pos = 0; this.n...原创 2019-04-11 16:57:07 · 648 阅读 · 0 评论 -
js 选择排序
第一个元素和其他元素进行比较,检查完所有元素后,最小元素会被放到数组的第一个位置,然后算法会从第二个位置继续。function CArray(numElements) { this.dataStore = []; this.pos = 0; this.numElements = numElements; this.insert = insert; ...原创 2019-04-11 16:25:00 · 347 阅读 · 0 评论 -
js 冒泡排序
如果数字按升序排序,比较相邻数据,如果左侧小于右侧,则交换数组,最大的数值在相邻比较中被漂浮到最右边。像气泡一样从数组的一端漂浮到另一端。function CArray(numElements) { this.dataStore = []; this.pos = 0; this.numElements = numElements; this.inser...原创 2019-04-11 15:51:07 · 172 阅读 · 0 评论