Grouping array data

B

Brad Foster

How can I group the following array data
1 9 101 I 1
1 9 101 I 2

1 9 101 I 3

1 9 101 I 3.5

1 9 101 II 41

1 9 101 II 42

1 9 101 II 43

1 9 102 I 1

1 9 102 I 2

Thanks
 
B

bm

Why don't you treat each array as a vector and
insert its elements in to a tree? So at the end you get:
1(9)
|
9(9)
--------------
| |
101(7) 102(2)
----------- |
| | |
I(3) II(4) I(2)
and so on. You can also have each node in the tree
have a count associated with it, if that is needed later on.
With one pass over the data, you have everything grouped.

does this help?
 
R

Roedy Green

How can I group the following array data

You can use RPG-like control break logic. where you sort the data by
fields, and write little routines to use at the start and end of each
group. I have a skeleton class for managing such code if you are
interested. The key is writing a differAt method that returns an int
that says which field the two records differ at.
 
?

=?ISO-8859-1?Q?Thomas_Gagn=E9?=

What exactly do you mean by grouping them? What kind of data structure
do you need/want as a result?
 
B

Brad Foster

The result i want is this

Get first column [1]
Process this--

Get second column [101 102]
Process this--

On third column [I,II],
Process this--

ON fourth col [1,2,3,3.4], [41,42,43] [1,2]
Process this--


Arrays are ok to use for each of these steps
 
A

ak

seems that you need Set.
add all data from first column to Set and you get just one value - 1 and so
on with second, third column....


Brad Foster said:
The result i want is this

Get first column [1]
Process this--

Get second column [101 102]
Process this--

On third column [I,II],
Process this--

ON fourth col [1,2,3,3.4], [41,42,43] [1,2]
Process this--


Arrays are ok to use for each of these steps


Thomas Gagné said:
What exactly do you mean by grouping them? What kind of data structure
do you need/want as a result?



--
.tom
remove email address' dashes for replies
opensource middleware at <http://isectd.sourceforge.net>
http://gagne.homedns.org
 
B

bm

You already have the data grouped in your tree.
Simply traverse the tree at different depths and
group the nodes that have the same parents.
For example:

getNodesAtDepth(1) gives the set {1}
getNodesAtDepth(2) gives the set { (101, 102) }
getNodesAtDepth(3) gives the set { (I, II), (I) }
getNodesAtDepth(4) gives the set { (1, 2, 3, 3.5), (41, 42, 43), (1, 2) }

does this help?


Brad Foster said:
The result i want is this

Get first column [1]
Process this--

Get second column [101 102]
Process this--

On third column [I,II],
Process this--

ON fourth col [1,2,3,3.4], [41,42,43] [1,2]
Process this--


Arrays are ok to use for each of these steps


Thomas Gagné said:
What exactly do you mean by grouping them? What kind of data structure
do you need/want as a result?



--
.tom
remove email address' dashes for replies
opensource middleware at <http://isectd.sourceforge.net>
http://gagne.homedns.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top