Grouping array data

Discussion in 'Java' started by Brad Foster, Oct 24, 2003.

  1. Brad Foster

    Brad Foster Guest

    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
     
    Brad Foster, Oct 24, 2003
    #1
    1. Advertisements

  2. bm

    bm Guest

    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$-nexis.com...
    > 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
    >
    >
    >
     
    bm, Oct 24, 2003
    #2
    1. Advertisements

  3. Brad Foster

    Brad Foster Guest

    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$-nexis.com...
    > > 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
    > >
    > >
    > >

    >
    >
     
    Brad Foster, Oct 24, 2003
    #3
  4. bm

    bm Guest

    Then they are already sorted in a tree. What do you mean by sorting then?


    "Brad Foster" <> wrote in message
    news:bnbo58$1l6$-nexis.com...
    > 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$-nexis.com...
    > > > 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
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    bm, Oct 24, 2003
    #4
  5. Roedy Green

    Roedy Green Guest

    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.
     
    Roedy Green, Oct 24, 2003
    #5
  6. Brad Foster

    Brad Foster Guest

    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.
     
    Brad Foster, Oct 24, 2003
    #6
  7. 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
     
    =?ISO-8859-1?Q?Thomas_Gagn=E9?=, Oct 24, 2003
    #7
  8. Brad Foster

    Brad Foster Guest

    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é" <> 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
    >
    >
     
    Brad Foster, Oct 24, 2003
    #8
  9. ak

    ak Guest

    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$-nexis.com...
    > 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é" <> 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
    > >
    > >

    >
    >
     
    ak, Oct 25, 2003
    #9
  10. bm

    bm Guest

    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$-nexis.com...
    > 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é" <> 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
    > >
    > >

    >
    >
     
    bm, Oct 25, 2003
    #10
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. grouping array

    , Sep 29, 2005, in forum: Python
    Replies:
    8
    Views:
    471
    Michael Spencer
    Sep 30, 2005
  2. neda

    grouping data of array

    neda, Aug 1, 2011, in forum: Java
    Replies:
    2
    Views:
    587
    javabudy
    Aug 6, 2011
  3. Debbie Davis

    Grouping totalling maybe an array?

    Debbie Davis, Oct 19, 2004, in forum: ASP General
    Replies:
    6
    Views:
    313
    Debbie Davis
    Oct 20, 2004
  4. Sam Kong

    Grouping elements of an array?

    Sam Kong, Jan 8, 2007, in forum: Ruby
    Replies:
    6
    Views:
    263
    Sam Kong
    Jan 8, 2007
  5. Sam Kong
    Replies:
    5
    Views:
    455
    Peña, Botp
    Oct 22, 2007
Loading...

Share This Page