void Graph::max_path(){
for(int i=0; i <N; i++){
cost[i]=0; cam_max[i]=999;
}
// Percorre todos os vertices adjacentes do vertice
int max = 0;
list<int>::iterator i;
for (int a = 0; a < N ; a++){
int v = ordely[a];
for (i = adj[v].begin(); i != adj[v].end(); ++i){
int viz = *i;
if (cost[viz]<cost[v]+1){
cost[viz] = cost[v]+1;
if(cost[viz]>max) max = cost[viz];
}
}
}
cout << "\nCusto maximo " << max;
}
I need to convert this C++ program to a python program... However, I'm struggling to understand what this adj[v].begin() inside the for loop means. Can anyone explain it to me, please?
.begin()and.end()are member functions on STL containers (in your case a list container). As for what they are, they are pointers to the beginning and the end + 1 of your list, respectively. Thelist<int>::iteratoris an abstraction for performing pointer arithmetic given to you by the STL. Does that answer your question?adjis declared.adjis defined, It seems that you are indexing intoadjand accessing the.begin()member function of the indexed element. Think alistoflist.