Renasha Silva Renasha Silva - 9 months ago 22
C++ Question

find the slist value which is the value for a specific key in map

I have a map with a int as the key and a slist as the value. slist is singly linked link list. (like https://www.sgi.com/tech/stl/Slist.html)
how do I get the specific slist for the key that I am looking in the map.

the code is below:

struct ListElemnts{
in a;
string b;
};

slist<ListElemnts *> element;

typedef std::map<int,slist<ListElemnts *> > hashmapList;

struct ListElemnts* pElement = (struct ListElemnts*) malloc(sizeof(struct ListElemnts));

hashmapList.insert(pair<int , slist<ListElemnts *> >(2,pElement));
hashmapList.insert(pair<int , slist<ListElemnts *> >(1,pElement));

map<int , slist<ListElemnts*> >::iterator it = hashmapList.begin();
it = hashmapList.find(1);
if (it != hashmapList.end())
{
//how do i get the slist for the 'it' i find and assign it to the below slsist to iterate via it
slist<ListElemnts *>::iterator position;
}


how to get the slist for the specific it key??

P0W P0W
Answer Source

how to get the slist for the specific it key??

Like following:

slist<ListElemnts *>::iterator position = it->second.begin();