473,385 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Sorting a map

39
i have 2 maps like below:

Expand|Select|Wrap|Line Numbers
  1. typedef std::map<std::string, ObjA> MapA;
  2. typedef std::map<ObjA, std::string> MapB;
  3.  
  4. MapA mapa;
  5. MapB mapb;
they are actually pretty same maps, just key and value are swaped.

i want to find out whether or not a value (which is string) is in the mapB like this
Expand|Select|Wrap|Line Numbers
  1. ObjA function (const char * value){
  2. for (MapB::const_iterator it = _mapb.begin(); it != _mapb.end(); ++it){
  3.  // how do i fill here.. 
  4.  // mapb is something like this:
  5.  // mapb <ObjA, value>
  6.  // like how to check if it == value and return ObjA
  7. }
  8. }
  9.  
Thanks in advance
Jan 21 '08 #1
2 1431
gpraghuram
1,275 Expert 1GB
i have 2 maps like below:

Expand|Select|Wrap|Line Numbers
  1. typedef std::map<std::string, ObjA> MapA;
  2. typedef std::map<ObjA, std::string> MapB;
  3.  
  4. MapA mapa;
  5. MapB mapb;
they are actually pretty same maps, just key and value are swaped.

i want to find out whether or not a value (which is string) is in the mapB like this
Expand|Select|Wrap|Line Numbers
  1. ObjA function (const char * value){
  2. for (MapB::const_iterator it = _mapb.begin(); it != _mapb.end(); ++it){
  3.  // how do i fill here.. 
  4.  // mapb is something like this:
  5.  // mapb <ObjA, value>
  6.  // like how to check if it == value and return ObjA
  7. }
  8. }
  9.  
Thanks in advance
Check this code

Expand|Select|Wrap|Line Numbers
  1. ObjA check(const char * value)
  2. {
  3.     for (MapB::const_iterator it = mapb.begin(); it != mapb.end(); ++it)
  4.     {
  5.         if (strcmp((*it).second.c_str(),value) == 0)
  6.         {
  7.             return (*it).first;
  8.         }
  9.      }
  10. }
  11.  
Raghuram
Jan 22 '08 #2
weaknessforcats
9,208 Expert Mod 8TB
strcmp is deprecated in C++. Use the string type.

Expand|Select|Wrap|Line Numbers
  1. ObjA check(const string&  value)
  2. {
  3.     for (MapB::const_iterator it = mapb.begin(); it != mapb.end(); ++it)
  4.     {
  5.         if ((*it).second == value)
  6.         {
  7.             return (*it).first;
  8.         }
  9.     }
  10. }
  11.  
There should be no C strings in a C++ program.
Jan 22 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys()...
0
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update...
7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
10
by: Sjaakie | last post by:
Hi, I'm, what it turns out to be, fooling around with 3-tier design. At several websites people get really enthusiastic about using custom dataobjects instead of datasets/-tables. While trying to...
4
by: Ambica Jain | last post by:
Hi, I want custom sorting on some of the columns in the datagrid. And i am able to do the same by overriding MouseDown event. However, i need to rebind my datatable to reflect the changes in...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
1
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
5
by: lemlimlee | last post by:
hello, this is the task i need to do: For this task, you are to develop a Java program that allows a user to search or sort an array of numbers using an algorithm that the user chooses. The...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.