|
-
Jan 9th, 2008, 05:18 AM
#1
Thread Starter
Hyperactive Member
Iterator For Multidimensional Vector
I'm having trouble wrapping my head around this idea/concept.
I know how an iterator works for a single dimension vector. You have the reverse iterator and the forward iterator. I would assume that you can have iterators for multidimensional vectors as well. However if you wanted to print the contents of the multidimensional vector, would you have to have an iterator for each dimension or could you use a single iterator to navigate though the vector in a row-by-row fashion?
-
Jan 9th, 2008, 03:34 PM
#2
Re: Iterator For Multidimensional Vector
Having never tried it with iterators.. I'm unsure.. I assume its the same though..
Code:
vector<vector<int>> testVector;
vector<vector<int>>::iterator it;
it = testVector.begin();
++it;
etc..
Vectors are random access anyway.. so you can just as easily do this:
Code:
vector<vector<int>> testVector;
cout << testVector[x][y];
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Jan 10th, 2008, 02:31 PM
#3
Thread Starter
Hyperactive Member
Re: Iterator For Multidimensional Vector
I asked around on the CProgramming forums and apparently you can have something like this (assuming that I have a multidimensional vector set up):
Code:
vector<int>::iterator forwardDim1;
vector< vector<int> >::iterator forwardDim2;
You'd need an iterator for each dimension in the vector. I was just trying to think of another way to access the elements of the vector besides for the for loop method.
-
Jan 10th, 2008, 06:14 PM
#4
Re: Iterator For Multidimensional Vector
Yeah.. that makes sense. Strange that I completely missed that second part when I replied! Stupid brain of mine!
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|