Skip to main content

Vectors within Vector

1 reply [Last post]
adilsun
Offline
Joined: 2004-12-14
Points: 0

Hi,

I need to hold vector within vector to hold data. At run time I don't know how many vectors will be created. Each top vector will hold other vectors and those other vectors can hold other sub vectors
and the new iteration will have new top vector and so on the cycle go on.

eg:

0 top vector ===> sub vector 1 ==> sub vector 2
1 top vector ===> sub vector 1 ==> sub vector 2
===> another sub vector 1 ==> another sub vector 2
2 top vector ===> sub vector 1 ==> sub vector 2

We have two for loops

for rows
for columns

Hope I am clear in my question,

Thanks in advance,

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
adilsun
Offline
Joined: 2004-12-14
Points: 0

Hi,

I need to hold vector within vector to hold data. At run time I don't know how many vectors will be created. Each top vector will hold other vectors and those other vectors can hold other sub vectors
and the new iteration will have new top vector and so on the cycle go on.

eg:

0 top vector ===> sub vector 1 ==> sub vector 2
1 top vector ===> sub vector 1 ==> sub vector 2
===> another sub vector 1 ==> another sub vector 2
2 top vector ===> sub vector 1 ==> sub vector 2

We have two for loops

for rows
for columns

I need to create new Top vector on each new top level object that is in the data.

It is not the row for loop that tells us that top level object has come, but rather it is the column index of the objects that tell whether it is a top level object or sub-level or of the level lower than that sub level; ie; I have to put those objects at appriopriate levels...

eg if I print a top most Vector which has many top level Vectors and many sub level Vectors of each of them, I may get:

[[2001 [ [Feb [7] ] , [March,[3,18]] ],[2002]]
ie 2001 has Feb 7 and 3 and 18 March
there is 2002 only.

to pick
Column===== 1 = 2 = 3 --- Action to be taken
row 1====>2001 =====> create new top level vector here
row 2========>Feb =====> create new sub level vector here and put it in top level (in vector of level preceding it)
row 3============>7 =====> create new vector here and put it in vector of level preceding it
row 4========>March =====> add to the sub level vector created at Feb 2001
row 5============>3 =====> create new vector here and put it in vector of level preceding it
row 6============>18 =====> add to the sub level vector created at March 3 2001
row 7====>2002 =====> create new top level vector here

but the problem is we cannot assume at runtime that the number will be same ie 3 levels. It may have more than that or less than that!

Otherwise I would have a
Vector data
===== holding top level vectors ===== they would have been holding sub level vectors which in turn could have had date vectors.

As the data could be dates or some other types... our design would have to be such that it can hold all that information. The data I showed in row and columns would always have levels defined in that pattern.

Hope I am clear in my question,

Thanks in advance,