5 Replies - 9815 Views - Last Post: 20 May 2009 - 10:04 AM Rate Topic: -----

#1 tashe  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 107
  • Joined: 10-March 09

Array of lists of lists

Posted 20 May 2009 - 09:33 AM

Hi
Is this valid in C++:

list<list<int>> paths[8];

because I am having some errors trying to iterate through it with an iterator.
thanks
Is This A Good Question/Topic? 0
  • +

Replies To: Array of lists of lists

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3088
  • View blog
  • Posts: 19,136
  • Joined: 14-September 07

Re: Array of lists of lists

Posted 20 May 2009 - 09:38 AM

An array of list lists? Why in the world would you do that? Could you post the code you're using? :\
Was This Post Helpful? 0
  • +
  • -

#3 tashe  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 107
  • Joined: 10-March 09

Re: Array of lists of lists

Posted 20 May 2009 - 09:43 AM

The code is too big and not with english variables and comments. I'll explain:

I need to find all the paths from point A to point Z in a graph. So i need to keep all the paths that start with A and finish with Z, but are going through different nodes in between these 2 nodes.
example:

A - b - f - Z
A - b - t- u - o - Z
So i figured i should use a list for each path, and make a list of all the paths i.e. list of lists.
I think that's the best way.
Was This Post Helpful? 0
  • +
  • -

#4 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3088
  • View blog
  • Posts: 19,136
  • Joined: 14-September 07

Re: Array of lists of lists

Posted 20 May 2009 - 09:51 AM

OK, a list of lists sounds fine for that, but why do you need an array of list lists?
Was This Post Helpful? 0
  • +
  • -

#5 tashe  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 107
  • Joined: 10-March 09

Re: Array of lists of lists

Posted 20 May 2009 - 09:56 AM

because I have 8 nodes and need to store the paths from A to each node.
Was This Post Helpful? 0
  • +
  • -

#7 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3088
  • View blog
  • Posts: 19,136
  • Joined: 14-September 07

Re: Array of lists of lists

Posted 20 May 2009 - 10:04 AM

How are you iterating through it? I can compile a small test fine:

#include <iostream>
#include <list>
using namespace std;

int main()
{
	list<list<int>> paths[8];
	list<list<int>>::iterator iter;

	for(int i = 0; i < 8; i++)//each path
	{
		for(iter = paths[i].begin(); iter != paths[i].end(); iter++)
		{
			//do something
		}
	}
}



The iterator has to know the structure of your STL container. Since you have an array, you need to use the subscript operator to tell it which one you're going to be traversing, playing around with, etc...
Was This Post Helpful? 1

Page 1 of 1