List of Lists

I'm trying to work with a list of lists for a node array, and I can't get the iterator to work correctly. The list it the Standard version in the library. I can't get the iterator to the sub-list to use any functions. Any help?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

struct coords
{
  float lat;
  float lon;
};

struct city
{
  string name; 
  coords location;
};

struct vertex
{
  string name;
  float weight; 
};

class Graph
{
  private:
    int m_size;
    list< list<vertex> > m_edges;
    list<city> m_locations;
  
  public:
    void addVertex( city location, list<vertex> edges );
    void addEdge( city location, vertex* edge);
    void populateEdges();
    void buildMST();
};

void Graph::addVertex( city location, list<vertex> edges)
{
  m_locations.push_back( in);
  m_edges.push_back(edges);
  vertex self; 
  self.weight = 0;
  self.name = in.name;
  list<vertex>::iterator start = m_edges.begin()->begin();
  start->pushback(self); // error 1
}

void Graph::addEdge( city location, vertex edge)
{
  list< list<vertex>* >::iterator iter;
  list< vertex >::iterator data;
  for( iter = m_edges.begin(); iter != m_edges.end(); iter++)
  {
    data = iter->begin();
    if( data->name == location.name)
    {
       iter->push_back(edge); // error 2
    }
  }
}


1. 'struct std::_List_iterator<vertex>' has no member named 'pushback'
2. no matching function for call to `std::list<vertex, std::allocator<vertex> >::push_back(vertex*&)'
Last edited on
just to clarify the code:

iter references an element of m_edges (which is a pointer to another list)

data references the first element of this list mentioned above

which list are you trying to push_back onto?
to fix errors 1 and 2, use (*iter)->begin() rather than iter->begin()
Edges is a list of lists. Not, pointers, I fixed that mistake.

Data is an iterator for a list of vertexes, a sub-list of m_edges.

I am trying to push onto a sub-list of m_edges.
ok
then it should probably be data->push_back(edge)
Topic archived. No new replies allowed.