JavaScript数据结构&算法
1 数据结构
1.1 数组Array
1.2 栈Stack
1.3 队列Queue
1.4 链表LinkedList
1.5 集合Set
let mySet = new Set();
mySet.add(1);
mySet.add('hello world');
let o = { a: 1, b: 2 };
mySet.add(o);
mySet.add({ a: 1, b: 2 });
const has = mySet.has(1);
const has2 = mySet.has(3);
mySet.delete(2);
const size = mySet.size;
for(let item of mySet) {console.log(item)
}
for(let item of mySet.keys()) {console.log(item)
}
for(let item of mySet.values()) {console.log(item)
}
const arr = [...mySet];
const arr2 = Array.from(set);
const set = new Set([1,3,5]);
const intersection = new Set([...mySet].filter(x => set.has(x)));
const difference = new Set([...mySet].filter(x => !set.has(x)))
1.6 字典Map
const map = new Map();
map.set('a','aa');
map.set('b', 'bb');
map.has('a');
map.has('c');
map.get('a');
map.get('b');
map.delete('b');
map.clear();
map.set('a', 'aaaaa');
1.7 树Tree
1.8 图
1.9 堆Heap
2 算法