struct nodeType
{
int v, index;};
list<nodeType> node[1000];
for(list<nodeType>::iter = node[q[qIndex]].begin();
iter != node[q[qIndex]].end(); iter++)
What's wrong with it? how can i fix it?
As already pointed out, node[1000] is one thousand (empty) elements of
the type: list<nodeType>
I doubt that was the intention.
Like most containers, a construct is available to create a loaded
container.
std::list< node > nodes(1000);
Thats one list with 1000 node elements
The question is: in what state are those elements?
If you are planning to use a zero indexed sequenced container, why not
just:
std::vector< int > v(1000, 0); // poof - instant index, all nodes
intialized
Your list has a begin() and end() member function that return the
first element and one past the last element as passed to the std::copy
algo below...
#include <iostream>
#include <ostream>
#include <list>
#include <algorithm>
#include <iterator>
struct node
{
int index;
int value;
node() : index(0), value(0) { }
node(int i, int v) : index(i), value(v) { }
};
std:
stream& operator<<(std:
stream& os, const node& n)
{
os << "index: " << n.index;
os << "\tvalue: " << n.value;
return os;
}
int main()
{
std::list< node > container(10);
std::copy( container.begin(),
container.end(),
std:
stream_iterator< node >(std::cout, "\n") );
}
/*
index: 0 value: 0 // 10 times
*/