Consider the following code snippet, taken for a program that works fine.
As you can see, It uses 2 nested for loops to iterate through a vector of vectors:
#define VERTEXES 10
vector<int> adjacency_list[VERTEXES];
for ( int index = 0; index < VERTEXES; index++ ){
cout << "List[" << index << "]: ";
for (auto element : adjacency_list[index])
cout << element << ", ";
cout << ".\n";
}
Could the first for be replaced by a ranged for too, in order to make the code simpler? If so, how?
If it makes the code more complex I'm not interested, thank you. But, in this case, an explanation of why it cannot make the code simpler is welcome!