Https://ide.codingblocks.com/s/44894

sir…in this question i m creating a graph
sir in the line 19 for printing purpose i used auto since i did not know the data type…
in the main program i have entered string snd strign type so what should be the type in the for loop instead of auto…
in simple words i want to say if i create graph for string string type what would be used instead of auto…
thank you

Hey Rahul, your i is basically storing the address of a pair of <t,list<t>>, in this code your t is string so i is giving the address of a pair of<string,list>`. And in this code you are building a generic graph which can have key of any data type, So its better to use auto to iterate over the map.

sir…r u saying the variable i declare after auto to iterate is basically a pointer…right??

Yes,i is a pointer that will iterate on your adjlist.

Sir so why don’t we put auto* or int * something like that…?

you can use auto* but there is no need of that in your code.

Conceptually we should use * there …but it works without* as well right??

Yes, because auto can behave by value, by reference and as pointer also.

i used auto* …it’s not working…

Hey Rahul, I have used auto* in your code and its working fine. Here is the code for print() using auto*

void print(){
        for(auto* i:adjlist){
            cout<<i.first<<"->";
            for(auto* j:adjlist[i.first]){
                cout<<j<<",";
            }
            cout<<endl;   
        }
    }

i m afraid sir it’s not working…

Hey Rahul, no need to worry buddy… I am sharing your updated code you can check this its working properly.