Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Graph c++

Status
Not open for further replies.

TotalInsanity

Programmer
Oct 18, 2006
20
GB
Hello All.

I could do with some expert help here, so here goes to all you gurus!

I have created a 'map within a map' to form a graph structure in c++.

I have declared it like this:
Code:
typedef map<string, double> stringVector; //map of doubles indexed by strings
typedef map<string, stringVector> graph;  //a two-dimensional sparse array, indexed by strings and holding double values

I have created an instance as follows:
Code:
graph distanceMap;   // declare the graph that holds the map

My graph structure holds placename and location data and I have added it to the structure like this:
Code:
distanceMap["Nottingham"]["Coventry"] = 52.65;

When I look at the map in the debugger it shows me that:

[0] Nottingham - First = Nottingham, Second = [0] Coventry, 52.65

With First and Second being map iterators.

My question here really is that in a normal multimap I can access the data using
Code:
iteratorname->first and iteratorname->second
and it would display the data held in the map.

Using the structure I have shown above, I am unsure how I access the second maps data and edges.

If I use a find() on my structure it will find say ("Nottingham") and will have an iterator pointing to this data entry, but then how do I access the second keys values?? (i.e. Coventry and the double data (52.65).

I have tried loads of things now and I am tearing my hair out!

Can one of you experts help me out here so I can access the structures data please??

If you want more info just ask here and I'll provide it!

Thanks in advance Gurus! Blue Peter badges for anyone that helps :OP
 
Please ignore my stupid questions.

If you do know a better way than using the following code please still shout up.

I am using:
Code:
distanceMap["Nottingham"]["Coventry"] which will return the value I want of 52.65 without using the iterators. 

Need more coffee :O)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top