
数据结构
quan!!!
这个作者很懒,什么都没留下…
展开
-
JavaScript实现双向链表(ES5动态原型模式)
双链表结构function DoubleLinkedList() { var Node = function(element) { this.element = element; this.next = null; this.prev = null; }; this.length = 0; this.head = n...原创 2019-01-31 17:58:48 · 234 阅读 · 0 评论 -
JavaScript实现单链表(ES5动态原型模式)
单链表的数据结构如下:function LinkedList() { //结点指针类 var Node = function(element) { this.element = element; this.next = null; }; //链表长度 this.length = 0; //链表头指针 th...原创 2019-01-31 11:53:23 · 303 阅读 · 0 评论 -
JavaScript实现字典(ES5动态原型模式)
字典的结构function Dictionary () { this.items = {}; if(typeof this.set != 'function') { Dictionary.prototype.has = function(key) {}; Dictionary.prototype.set = function(key, value)...原创 2019-02-10 23:03:22 · 615 阅读 · 0 评论 -
JavaScript实现孩子表示法的二叉排序树(ES5动态原型模式)
树的结构function BinarySearchTree() { var treeNode = function(element) { this.key = element; this.leftNode = null; this.rightNode = null; }; this.root = null; if(t...原创 2019-02-10 20:43:58 · 156 阅读 · 0 评论 -
JavaScript实现集合(ES5动态原型模式)
集合的概念集合是由一组无序且唯一(即不能重复)的项组成的。这个数据结构使用了与有限集合相同的数学概念,但应用在计算机科学的数据结构中。你也可以把集合想象成一个既没有重复元素,也没有顺序概念的数组。集合的结构function Set() { this.items = {}; if (typeof this.add != 'function') { Set.pr...原创 2019-02-09 10:38:50 · 317 阅读 · 0 评论 -
JavaScript实现循环队列(ES5动态原型模式)
循环队列的一个例子就是击鼓传花游戏需要原队列结构function Queue() { this.items = []; if (typeof this.enqueue != 'function') { Queue.prototype.enqueue = function(element) { this.items.push(elemen...原创 2019-02-08 15:52:22 · 332 阅读 · 0 评论 -
JavaScript实现优先队列(ES5动态原型模式)
优先队列结构function PriorityQueue() { this.items = []; function QueueElement (element, priority) { this.element = element; this.priority = priority; } if (typeof this.enqueue != 'funct...原创 2019-02-08 15:13:04 · 219 阅读 · 0 评论 -
JavaScript实现普通队列(ES5动态原型模式)
队列结构function Queue() { this.items = []; if (typeof this.enqueue != 'function') { Queue.prototype.enqueue = function(element) { this.items.push(element); }; ...原创 2019-02-08 14:40:10 · 197 阅读 · 0 评论 -
JavaScript实现栈并解决进制转换问题
首先实现栈类 function Stack () { this.items = []; // 添加栈元素 Stack.prototype.push = function(element) { this.items.push(element); } // 移除栈顶元素并返回 Stack.prototype...原创 2019-01-29 12:03:22 · 207 阅读 · 0 评论 -
JavaScript实现散列表(ES5动态原型模式)
散列表的概念HashTable类,也叫HashMap类,是Dictionary类的一种散列表实现方式。散列算法的作用是尽可能快地在数据结构中找到一个值。如果要在数据结构中获得一个值(使用get方法),需要遍历整个数据结构来找到它。如果使用散列函数,就知道值的具体位置,因此能够快速检索到该值。散列函数的作用是给定一个键值,然后返回值在表中的地址。...原创 2019-02-11 12:31:58 · 313 阅读 · 0 评论