dimanche 8 novembre 2020

What is the difference between (*it).first and it->first?

What is the difference between (*it).first and it->first?

Can they be used interchangeably, for example in the below code? Also, would really help if someone has a good resource where I can learn about iterators. Specifically about this line vector<pair<int, int>>:: iterator it; Can someone explain it?

vector<pair<int, int>> adj[10005]; //For storing vertices, weights of a directed graph as an adjacency list

for(int i = 1; i <= V; i++)//GOING THROUGH EACH VERTEX
{
  vector<pair<int, int>>:: iterator it;
  for(it = adj[i].begin(); it != adj[i].end(); it++)
  {
   cout<<it->first<<" ";
   cout<<it->second<<"\n";
  }
}

Aucun commentaire:

Enregistrer un commentaire