Reverse map lookup

前端 未结 8 830
囚心锁ツ
囚心锁ツ 2020-11-30 05:37

I have a 1 to 1 map. What\'s the best way to find keys from values,

i.e.

For examples if the map is this

KEY VALUE

a    1
b    2
c          


        
8条回答
  •  感情败类
    2020-11-30 06:17

    I know this is a really old question but this codeproject article (http://www.codeproject.com/Articles/3016/An-STL-like-bidirectional-map) is a pretty good example of a bidirectional map.

    This is an example program that shows how easy it is:

     #pragma warning(disable:4503)
    
        #include "bimap.h"
        #include 
        #include 
    
        using codeproject::bimap;
    
        int main(void)
        {
          bimap bm;
    
          bm[1]="Monday";
          bm[2]="Tuesday";
          bm[3]="Wednesday";
          bm[4]="Thursday";
          bm[5]="Friday";
          bm[6]="Saturday";
          bm[7]="Sunday";
    
          std::cout<<"Thursday occupies place #"<

提交回复
热议问题