zoukankan      html  css  js  c++  java
  • 二叉搜索树3

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <map>
     4 #include <string>
     5 
     6 using namespace std;
     7 
     8 // map与multimap
     9 // 是键值映射容器
    10 // 内部是变体的红黑二叉树
    11 // 一对一,一对多
    12 
    13 int main()
    14 {
    15     //
    16     map<int,const char *> m;
    17 
    18     m.insert(make_pair(1,"ONE") );
    19     m.insert(make_pair(10,"TEN") );
    20 
    21     m[100]="HUNDRED";
    22 
    23     map<int,const char *>::iterator it;
    24 
    25     it=m.find(1);
    26     puts(it->second);
    27 
    28     it=m.find(2);
    29     if(it==m.end())
    30     {
    31         puts("NOT find");
    32     }
    33     else
    34     {
    35         puts(it->second);
    36     }
    37 
    38     puts(m[10]);
    39 
    40     m.erase(10);
    41 
    42     cout<<endl;
    43     for(it=m.begin();it!=m.end();++it)
    44     {
    45         puts(it->second);
    46     }
    47 
    48     m.insert(make_pair(3,"THREE") );
    49     m.insert(make_pair(4,"FOUR") );
    50     m.insert(make_pair(5,"FIVE") );
    51 
    52     cout<<endl;
    53     // 查找小于等于4的最后一个元素
    54     cout<<m.equal_range(4).first->second<<endl;
    55     // 查找大于5的第一个元素
    56     cout<<m.equal_range(4).second->second<<endl;
    57     
    58     
    59     // multimap与map类似
    60     // 可用count计算键对应值的数量
    61 
    62     return 0;
    63 }

    #include <iostream>#include <cstdio>#include <map>#include <string>
    using namespace std;
    // map与multimap// 是键值映射容器// 内部是变体的红黑二叉树// 一对一,一对多
    int main(){    //    map<int,const char *> m;
        m.insert(make_pair(1,"ONE") );    m.insert(make_pair(10,"TEN") );
        m[100]="HUNDRED";
        map<int,const char *>::iterator it;
        it=m.find(1);    puts(it->second);
        it=m.find(2);    if(it==m.end())    {        puts("NOT find");    }    else    {        puts(it->second);    }
        puts(m[10]);
        m.erase(10);
        cout<<endl;    for(it=m.begin();it!=m.end();++it)    {        puts(it->second);    }
        m.insert(make_pair(3,"THREE") );    m.insert(make_pair(4,"FOUR") );    m.insert(make_pair(5,"FIVE") );
        cout<<endl;    // 查找小于等于4的最后一个元素    cout<<m.equal_range(4).first->second<<endl;    // 查找大于5的第一个元素    cout<<m.equal_range(4).second->second<<endl;            // multimap与map类似    // 可用count计算键对应值的数量
        return 0;}

  • 相关阅读:
    基于Windows Mobile 5.0的GPS应用程序开发
    iis6应用程序池被自动禁用问题 应用程序池'DefaultAppPool' 被自动禁用
    Axapta物流模块深度历险(八)
    AX的报表服务器(一)
    AX的企业门户(一)
    SQL Server2005 Reporting Services 管理站点
    SQL Server2005 Reporting Services的卸载
    耐心的解决问题
    危险操作符
    慢慢的坚持啊
  • 原文地址:https://www.cnblogs.com/jishuren/p/12269652.html
Copyright © 2011-2022 走看看