473,320 Members | 1,766 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,320 software developers and data experts.

how to build a recursive map ?

Hi,

When I want build a tree I define the structure below:

struct node
{
string data;
node *leaf;
node *right;
};
I want to define a map where each element is a map. Something similar to:

map<string, map *> m1;
Any idea ?

Thanks,
Jose Luis.
Jul 22 '05 #1
4 7601
jose luis fernandez diaz wrote:

I want to define a map where each element is a map. Something similar to:

map<string, map *> m1;


This is not a map of maps, it is a map of pointers to maps.
Anyway: what is your problem?

lets say you have a map, which maps int to double

map< int, double >

you now want to build a map out of this, such that a string
selects the map which maps int to double.

map< string, map< int, double > >

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #2

"jose luis fernandez diaz" <jo**********************@yahoo.es> wrote in
message news:c2**************************@posting.google.c om...
Hi,

When I want build a tree I define the structure below:

struct node
{
string data;
node *leaf;
node *right;
};
I want to define a map where each element is a map. Something similar to:

map<string, map *> m1;
Any idea ?

Thanks,
Jose Luis.


Like this

class Recursive
{
public:
...
private:
map<string, Recursive*> m1;
};

john
Jul 22 '05 #3
Karl Heinz Buchegger <kb******@gascad.at> wrote in message news:<40**************@gascad.at>...
jose luis fernandez diaz wrote:

I want to define a map where each element is a map. Something similar to:

map<string, map *> m1;


This is not a map of maps, it is a map of pointers to maps.
Anyway: what is your problem?

lets say you have a map, which maps int to double

map< int, double >

you now want to build a map out of this, such that a string
selects the map which maps int to double.

map< string, map< int, double > >


I need something like this:

template<class key, class T, . . .>
class map
{
typedef Key key_type;
// typedef T mapped_type;
typedef map *mapped_type;

. . .
}

map<string> m1;
m1["one"] = NULL;
m2["two"] = m1;

but I think that it is not posible.

I tried to simulate it with:

map<string, map<string, map<string ... string> . . . > m_n;

m_1["one"] = "zero";
m_2["two"] = m1["one];
.. . .
m_n["n"] = n_n_1["n-1"];
but this is ugly.

Regards,
Jose Luis.
Jul 22 '05 #4
jo**********************@yahoo.es (jose luis fernandez diaz) wrote in message news:<c2**************************@posting.google. com>...
Hi,

When I want build a tree I define the structure below:

struct node
{
string data;
node *leaf;
node *right;
};
I want to define a map where each element is a map. Something similar to:

map<string, map *> m1;
Any idea ?

Thanks,
Jose Luis.


try

map<string, void*>

and cast the void* to a map<string, void*> internally and so on. you
stop when the pointer is null.

to add elements to such thing:

map<string, void*> leaf1, leaf2;
leaf1["aa"] = 0;
laef2["bb"] = 0;

map<string, void*> node1;
node1["leaf1"] = leaf1;
node1["leaf2"] = leaf2;

dan
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Hung Jung Lu | last post by:
Hi, Does anyone know whether there is any generic GUI-based build system around? (Python-based would be great. Also, for now I am only looking for Windows OS.) By "build system" I mean something...
8
by: ted | last post by:
How does the speed of the Scons build tool compare with Ant? Right now with out Ant builds take around an hour. Hoping to speed that up. TIA, Ted
2
by: actuary77 | last post by:
I am trying to write simple recursive function to build a list: def rec(n,alist=): _nl=alist print n,_nl if n == 0: print n,_nl return _nl else:
1
by: Eugene | last post by:
Hi all, I have a page that uses JavaScript to continuously reload an image (Client-Pull method). Using Netscape v7.0 on Windows NT 4, Service Pack 6a, the images reload fine, but using...
0
by: Roland Hedberg | last post by:
Hi! This involves quite a lot of different system, so I'm not really sure who which would be the right list to query. So, I'm trying a couple, this list being one of them. I'm trying to...
0
by: dboileau | last post by:
Can anyone help me out with this error, I am trying to compile mysql with gcc 3.4.6 (Compiled from source) using CC=gcc CFLAGS="-O3 -mcpu=v8 -Wa,-xarch=v8plusa" \ CXX=gcc CXXFLAGS="-O3...
4
by: so.intech | last post by:
for example, ret = 0; for(i=0; i<3; i ++;) { for(j=0; j<4; j++;) { for(k=0; k<3; k++;) { for(m=0; m<4; m++;) {
2
by: hardieca | last post by:
Hi, I'm building a CMS and I'm banging my head against the wall over one part of the user interface. I have a Section entity which maybe have 0 or 1 parent Sections. So, as an example, I...
4
by: adato | last post by:
hello. I have a problem to build a recursive function The function gets an array of prices, an array of weight and and spesific Price. the output's function is the minimum weighet of the subset...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.