I am trying to use the 1st method viz. queue<pair<node *,int>>q but I am not able to access the node value using q.first.How can I can access the member variables of my custom class?
BFS traversal using 1st method i.e queue<pair<node *,int>>q
Hello @rohit_nandy i think the template which you are forming in that you are storing the node value i.e data at second value so you have to extract that using pair<node*,int>cur=q.front();
q.pop();
and then cout<<cur.second;
if you have any other doubt you can ask here:
Happy Learning!!
And what to do if I want to access cur.first ?How will i access only the first element?
@rohit_nandy if you have notices i have declared the cur as type like pair type only so if you will cout cur.first then it will give the that node address value.
Happy Learning!!
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.