zoukankan      html  css  js  c++  java
  • 数据结构----字典

    /*
    * 算法——字典
    * 字典是一种以键 - 值对形式存储数据的数据结构,Dictionay 类的基础是 Array 类。数组当对象用???
    * add: 增加元素
    * find:查找元素
    * remove:删除元素
    * */
    function add(key,value) {
        this.dataStore[key] = value;
    }
    function find(key) {
        return this.dataStore[key]
    }
    function remove(key) {
        delete this.dataStore[key];
    }
    //sort 能够有序输出 叫有序字典
    function showAll() {
        var keysArray = Object.keys(this.dataStore).sort();
        for (var i = 0 ; i < keysArray.length;i++) {
            console.log(keysArray[i] + "=====>" + this.dataStore[keysArray[i]]);
        }
    }
    function count() {
        var n = 0;
        for (var key in this.dataStore) {
            n++;
        }
        return n;
    }
    function clear() {
        for (var key in this.dataStore) {
            delete this.dataStore[key];
        }
    }
    function Dictionay() {
        this.dataStore = [];
        this.add = add;
        this.find = find;
        this.remove = remove;
        this.showAll = showAll;
        this.count = count;
        this.clear = clear;
    }
    
    var d = new Dictionay();
    
    d.add("name","张三");
    d.add("phone","15019222409");
    
    d.showAll();
    console.log(d.count())
  • 相关阅读:
    printf输出函数
    死循环的3种编写方案
    volatile 和const 变量的使用
    arm mov 指令
    arm ldr 指令
    arm str 指令
    Ztree-
    端口占用问题:java.net.BindException: Address already in use: bind
    模块和包
    序列化模块:json、pickle、shelve
  • 原文地址:https://www.cnblogs.com/yunnex-xw/p/9850584.html
Copyright © 2011-2022 走看看