• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Vector within vector

 
Ranch Hand
Posts: 473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,

Maki jav
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maki Jav wrote:Hope I am clear in my question...


Unfortunately, no. You didn't ask a question, you just described your design. What are your doubts?
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maki Jav wrote: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,

Maki jav




Ahh..... what's the question?


[EDIT: Wow. No posts for more than 30 minutes. Then I get beaten to a post by less than one minute ... ]
 
Maki Jav
Ranch Hand
Posts: 473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not able to pick that up clearly in those loops...

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.

Am I clear now?

Thanks,

Maki Jav

 
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, I see. (Or maybe I don't.)

You want to create a tree structure. Apparently each node of the tree is supposed to contain a Vector which in turn contains the child nodes of that node. Along with some other object which is the value of that node, or something.

Is that correct? And do you have a question about that?

Or perhaps you have a String representation of the tree which is sort of like XML or JSON, but not the same as either, so you're stuck writing your own customized parser for that String representation?

Is that correct? And do you have a question about that?
 
Henry Wong
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maki Jav wrote: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!



No need to assume -- the instanceof operator would be good here. If the element is an instanceof Vector, then you have another level to traverse. If the element is not, then it is one of the data types that you have to process.

Henry
 
Maki Jav
Ranch Hand
Posts: 473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
O my God, I am not clear!

The goal is to pick objects from that data I have. Nothing is a vector at that point. I want to put those Objects in vectors or any collection for that matter, so that I can use it latter and extract the data ie those Objects back. I would not have to be bothered anything else except, if a vector has a child, extract it, extract till I reach the last child.



Thanks,

Maki Jav
 
Paul Clapham
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maki Jav wrote:O my God, I am not clear!



No.

The goal is to pick objects from that data I have.



And is this going to be what the question is about, once you get around to asking it?
 
Maki Jav
Ranch Hand
Posts: 473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, but already have. I need help in picking up values ie objects in proper order so that the relation of parent and child is maintained...

I have a example code...
 
Paul Clapham
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maki Jav wrote:Yes, but already have.



I just looked through the thread and the only question you have asked is "Am I clear now?"

I have a example code...



Okay. Post that example code, and also the question you have about the example code. And any explanation the example code requires, such as assumptions about the data it receives and so on.
 
Maki Jav
Ranch Hand
Posts: 473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


But alas! Only the print statements correctly indicate what behaviour needs to followed; how to achieve that through code? Well, that beats me!

Do I need to have Hashtable/HashMap to hold Super level values and their subsequest child? How to go about it? What I need to code?
Please ignore Vector subElement or other code that may seem not correct. What the code tells is what is needed to be done at specific points in the program.


Thanks in advance,

Maki Jav
 
Maki Jav
Ranch Hand
Posts: 473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would this idea be okay with this code?


Step 1: Take a container, say a Vector, the top most one...

Step 2: Put values from first column of the table, considering it level one. Here 2011 and 2010

Step 3: Now against those values put Hashtable, and against those hashtables put more children Hashtables.

Vector
2010-- Hahstable --- key =2, value=Dec ie 12 --- Hashtable key = 3, value = 27

what you say and how to code that?

Thanks in Advance,

Maki Jav
 
Maki Jav
Ranch Hand
Posts: 473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Maybe I should create a class which will hold values in this fashion.

Top value-->
* sub value
index number
parent value to which this belongs

One to many relationships. and child upon child which in turn be a parent to its children.
 
Getting married means "We're in love, so let's tell the police!" - and invite this tiny ad to the wedding:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic