0

I have to combinatorially count all possible cases for a task. I want to make a tree for that purpose. There are several jobs and each job has several sub jobs. There are many agents available to do the jobs. Suppose Job1 Subjob1 can be done by Agent 1 or 2, then Job 1 Sub Job2 will be done by either of the agents. And then Job 2 will be started. and so on. Since nodes are varying and also the number of child nodes changes at different levels, my questions are:

  1. what is the best data structure to implement the same?

  2. what is the best way to traverse the tree using the data structure that you have recommended?

please give concrete C++/Java examples or web sources also rather than only abstract advise as I am green at coding.

EDIT:

Please refer to the flowchart for the tree that i have in mind.

enter image description here

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
userzizzy
  • 159
  • 1
  • 2
  • 11

1 Answers1

1

Hmmm, I don't think a tree is the best data structure for your requirements. I suggest a std::vector of Jobs. Each Job should have a container of subjobs

Your schedule can iterate through a vector much easier than a tree.

Edit 1: The code

class Subjob;
class Job
{
  std::vector<Subjob> other_jobs;
};

std::vector<Job> task_container;
Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
  • I can iterate easily thru `task_container` like: `vector::iterator it; for(it = task_container.begin(); it != task_container.end(); ++it)`. but how to use `iterator it` to access vector elements of `other_jobs`? Pls give code. – userzizzy Jan 28 '15 at 20:07
  • Iterating through vectors is all the same. For the member `other_jobs`, you would initialize an iterator, `std::vector::iterator`, to the beginning, `other_jobs.begin()`, and increment the iterator to point to the next element. – Thomas Matthews Jan 28 '15 at 20:15
  • So i will initialise the iterator `it` for the member `other_jobs` to the beginning as in `it.other_jobs.begin()` or `it->other_jobs.begin()`? – userzizzy Jan 28 '15 at 23:02