Sorting a 2 dimensional array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Todd

    Sorting a 2 dimensional array

    I'm new to c++ and was wondering how to sort a 2 dimensional array. I'm
    using a select sort for 1 dimensional arrays but it is not working for a 2
    dimensional array. The 2 dimensional array are float elements. Thanks in
    advance


  • Howard

    #2
    Re: Sorting a 2 dimensional array


    "Todd" <fthdg> wrote in message news:1075g2unck 7752b@corp.supe rnews.com...[color=blue]
    > I'm new to c++ and was wondering how to sort a 2 dimensional array. I'm
    > using a select sort for 1 dimensional arrays but it is not working for a 2
    > dimensional array. The 2 dimensional array are float elements. Thanks in
    > advance
    >
    >[/color]

    You don't specify anything at all about what you expect the results to be
    after sorting your 2D array. I'm not sure exactly what it means to sort a
    2D array!

    You can easily sort each row (or column, whatever), but then what? Must
    every element in the next row be greater (or less) than every element in the
    preceding row? Or is there some other criteria for what you desire? Is it
    a sparse array? Are elements allowed (or supposed) to move between columns
    as well as rows? See my problem? If you have a clear definition of the
    problem and its restrictions, the answer will likely be easy to see.

    Try working a small example on paper first, and that may help.

    By the way, this is not so much a C++ question as an algorithm question.
    Once you have a design, and implement it in C++ code, we can surely help you
    correct that code if it's giving you problems. But we can also help point
    you in the right direction initially, provided we have enough info.

    -Howard


    Comment

    • Howard

      #3
      Re: Sorting a 2 dimensional array


      "Todd" <fthdg> wrote in message news:1075g2unck 7752b@corp.supe rnews.com...[color=blue]
      > I'm new to c++ and was wondering how to sort a 2 dimensional array. I'm
      > using a select sort for 1 dimensional arrays but it is not working for a 2
      > dimensional array. The 2 dimensional array are float elements. Thanks in
      > advance
      >
      >[/color]

      You don't specify anything at all about what you expect the results to be
      after sorting your 2D array. I'm not sure exactly what it means to sort a
      2D array!

      You can easily sort each row (or column, whatever), but then what? Must
      every element in the next row be greater (or less) than every element in the
      preceding row? Or is there some other criteria for what you desire? Is it
      a sparse array? Are elements allowed (or supposed) to move between columns
      as well as rows? See my problem? If you have a clear definition of the
      problem and its restrictions, the answer will likely be easy to see.

      Try working a small example on paper first, and that may help.

      By the way, this is not so much a C++ question as an algorithm question.
      Once you have a design, and implement it in C++ code, we can surely help you
      correct that code if it's giving you problems. But we can also help point
      you in the right direction initially, provided we have enough info.

      -Howard


      Comment

      • Bill Seurer

        #4
        Re: Sorting a 2 dimensional array

        Todd wrote:
        [color=blue]
        > I'm new to c++ and was wondering how to sort a 2 dimensional array. I'm
        > using a select sort for 1 dimensional arrays but it is not working for a 2
        > dimensional array. The 2 dimensional array are float elements. Thanks in
        > advance[/color]

        Why is "it not working"? It should work the same way but you just have
        two sets of indices instead of one.

        Comment

        • Bill Seurer

          #5
          Re: Sorting a 2 dimensional array

          Todd wrote:
          [color=blue]
          > I'm new to c++ and was wondering how to sort a 2 dimensional array. I'm
          > using a select sort for 1 dimensional arrays but it is not working for a 2
          > dimensional array. The 2 dimensional array are float elements. Thanks in
          > advance[/color]

          Why is "it not working"? It should work the same way but you just have
          two sets of indices instead of one.

          Comment

          Working...