zoukankan      html  css  js  c++  java
  • (js描述的)数据结构[字典](7)

    (js描述的)数据结构[字典](7)

    一.字典的特点

    1.字典的主要特点是一一对应关系。
    2.使用字典,剋通过key取出对应的value值。
    3.字典中的key是不允许重复的,而value值是可以重复,并且字典中的key是无序的。
    

    在这里插入图片描述字典和映射关系; 字典和数组; 字典和对象;

    二.代码实现字典

    function Dictionary() {
                this.dic = {}
                // 1. add方法
                Dictionary.prototype.add = function(key, value) {
                    this.dic[key] = value
                }
                // 2.find方法
                Dictionary.prototype.find = function(key) {
                    return this.dic[key]
                }
                // 3.remove方法
                Dictionary.prototype.remove = function(key) {
                    delete this.dic[key]
                }
                // 4.showAll 方法
                Dictionary.prototype.showAll = function() {
                    var resultString = ''
                    for (var i in this.dic) {
                        resultString += i + '-->' + this.dic[i] + ' '
                    }
                    return resultString
                }
                // 5.size方法
                Dictionary.prototype.size = function() {
                    var res = Object.keys(this.dic)
                    return res.length
                }
                // 6.clear方法 
                Dictionary.prototype.clear = function() {
                    this.dic = {}
                }       
            }
    
  • 相关阅读:
    浅谈Huffman树
    CF884D:Boxes And Balls
    MySQL单表查询(重要)
    MySQL字段完整性约束(重要)
    MySQL数据类型(重要)
    数据库基本操作
    MySQL权限管理
    MySQL存储引擎概述
    数据库基础
    并发编程小结
  • 原文地址:https://www.cnblogs.com/jackson1/p/12682671.html
Copyright © 2011-2022 走看看