字典
字典数据结构是利用arr,基于object来实现的
function Dictionary() {this.dataStore = []this.add = addthis.remove = removethis.find = findthis.clear = clearthis.showAll = showAllthis.count = count}function add(k, v) {this.dataStore[k] = v}function remove(k) {delete this.dataStore[k]}function find(k) {return this.dataStore[k]}function clear() {this.dataStore = []}function showAll() {var keys = Object.keys(this.dataStore)for (var i = 0; i < keys.length; i++) {console.log(`key: ${keys[i]} --- value: ${this.dataStore[keys[i]]}`)}}function count () {return Object.keys(this.dataStore).length}var pDic = new Dictionary()pDic.add('a', 1)pDic.add('b', 2)pDic.add('c', 3)pDic.add('d', 4)console.log(pDic.find('c'))console.log(pDic.remove('c'))pDic.showAll()console.log(pDic.count())pDic.clear()console.log(pDic.count())
