Vector of lists of pairs of ints

Hi, I've never seen such nesting of types, but my professor sprung it on us for our final project this semester.

He was kind enough to make the code to load the information from our test files into this structure, but I don't understand how to get the information out of it (whether through iteration or in order to access certain parts to load the info into other objects to begin using and manipulating it).

So far, what I've come up with for iteration is this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <vector>
#include <list>
#include <cstdlib>

using namespace std;

int main()
{
	vector<list<pair<int,int> > > adj_list;
	
	for (vector<int>::iterator it = adj_list.begin(); it!=adj_list.end(); it++)
	{
		cout << *it << " ";
	}
	cout << "\n";
	return(EXIT_SUCCESS);
}


But it obviously doesn't work as I'm not taking to account any of the list or pair functionality (I also understand my adj_list is empty, but I just want to get this to compile my professor's code in my real project will help me load it once I understand how to output).

Can anyone please help?
vector<int>::iterator

Tell me what type of iterator that is and how it relates to the type of adj_list.
Ok, as I understand it, this is an iterator designed to go through a vector of integers (and I've done so in several projects).

So does that mean I need to change it to a vector<list>::iterator to iterate through a vector of lists?
Your professor is a jerk to do this, as no one can properly finish the project without understanding his twist.

Use a typedef to help in situations like this.

1
2
3
typedef pair <int, int>           point_t;
typedef list <point_t>            list_of_points_t;
typedef vector <list_of_points_t> list_of_list_of_points_t;

Now you can use it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
	list_of_list_of_points_t adj_list;

	for (list_of_list_of_points_t::iterator list_of_points_iter = adj_list.begin(); ...)
	{
		// *list_of_points_iter is a list_of_points_t.
		// You might want to use another loop to print the list of points:
		for (list_of_points_t::iterator point_iter = list_of_points_iter->begin(); ...)
		{
			// *point_iter is a point_t
			// Use the .first and .second items to get at it
			cout << "(" << point_iter->first
			     << "," << point_iter->second << ") ";
		}
		cout << "\n";
	}

Hope this helps.
Thanks. The nested for loop was what I needed. I think I understand how to access these things now and will be moving on to the various other challenges my professor has pulled out of his hat.
Topic archived. No new replies allowed.