Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Grouping array data

Reply
Thread Tools

Grouping array data

 
 
Brad Foster
Guest
Posts: n/a
 
      10-24-2003
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



 
Reply With Quote
 
 
 
 
bm
Guest
Posts: n/a
 
      10-24-2003
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?


"Brad Foster" <> wrote in message
news:bnbmsr$a9v$...
> 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
>
>
>



 
Reply With Quote
 
 
 
 
Brad Foster
Guest
Posts: n/a
 
      10-24-2003
actually these values are what I got from a tree!

any other way?


"bm" <> wrote in message
news:9odmb.12797$EO3.1824@clgrps13...
> 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?
>
>
> "Brad Foster" <> wrote in message
> news:bnbmsr$a9v$...
> > 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
> >
> >
> >

>
>



 
Reply With Quote
 
bm
Guest
Posts: n/a
 
      10-24-2003
Then they are already sorted in a tree. What do you mean by sorting then?


"Brad Foster" <> wrote in message
news:bnbo58$1l6$...
> actually these values are what I got from a tree!
>
> any other way?
>
>
> "bm" <> wrote in message
> news:9odmb.12797$EO3.1824@clgrps13...
> > 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?
> >
> >
> > "Brad Foster" <> wrote in message
> > news:bnbmsr$a9v$...
> > > 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
> > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-24-2003
On Fri, 24 Oct 2003 13:18:13 -0400, "Brad Foster"
<> wrote or quoted :

>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.


--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Brad Foster
Guest
Posts: n/a
 
      10-24-2003
actually i dont need to sort at all..all I need is a grouping


"Roedy Green" <> wrote in message
news:...
> On Fri, 24 Oct 2003 13:18:13 -0400, "Brad Foster"
> <> wrote or quoted :
>
> >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.
>
>
> --
> Canadian Mind Products, Roedy Green.
> Coaching, problem solving, economical contract programming.
> See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.



 
Reply With Quote
 
=?ISO-8859-1?Q?Thomas_Gagn=E9?=
Guest
Posts: n/a
 
      10-24-2003
What exactly do you mean by grouping them? What kind of data structure
do you need/want as a result?

Brad Foster wrote:

>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
>
>
>
>
>


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


 
Reply With Quote
 
Brad Foster
Guest
Posts: n/a
 
      10-24-2003
The result i want is this

Get first column [1]
Process this--

Get second column [101 102]
Process this--

On third column [I,II], [I]
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é" <> wrote in message
news:...
> What exactly do you mean by grouping them? What kind of data structure
> do you need/want as a result?
>
> Brad Foster wrote:
>
> >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
> >
> >
> >
> >
> >

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



 
Reply With Quote
 
ak
Guest
Posts: n/a
 
      10-25-2003
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" <> schrieb im Newsbeitrag
news:bnbtat$s6d$...
> The result i want is this
>
> Get first column [1]
> Process this--
>
> Get second column [101 102]
> Process this--
>
> On third column [I,II], [I]
> 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é" <> wrote in message
> news:...
> > What exactly do you mean by grouping them? What kind of data structure
> > do you need/want as a result?
> >
> > Brad Foster wrote:
> >
> > >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
> > >
> > >
> > >
> > >
> > >

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

>
>



 
Reply With Quote
 
bm
Guest
Posts: n/a
 
      10-25-2003
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" <> wrote in message
news:bnbtat$s6d$...
> The result i want is this
>
> Get first column [1]
> Process this--
>
> Get second column [101 102]
> Process this--
>
> On third column [I,II], [I]
> 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é" <> wrote in message
> news:...
> > What exactly do you mean by grouping them? What kind of data structure
> > do you need/want as a result?
> >
> > Brad Foster wrote:
> >
> > >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
> > >
> > >
> > >
> > >
> > >

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

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
grouping data of array neda Java 2 08-06-2011 07:50 AM
Grouping elements of an array? Sam Kong Ruby 6 01-08-2007 08:12 AM
Grouping values of a hash or array. Adrian Fraiha Ruby 2 08-04-2006 06:24 PM
grouping array pkilambi@gmail.com Python 8 09-30-2005 04:34 PM
Grouping totalling maybe an array? Debbie Davis ASP General 6 10-20-2004 03:30 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57