Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. sorting problem

sorting problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionalgorithms
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wong1907
    wrote on last edited by
    #1

    Hi, I am not good at programming. So, I hope somebody can help me to solve my problem. I already think it for a long time. My question is I have 2 set of datas. They are stored in variable no[i] and result[i]. no[0]=0.12 result[0]=medium no[1]=0.27 result[1]=medium no[2]=0.67 result[2]=short no[3]=0.43 result[3]=medium no[4]=0.98 result[4]=high no[i] and result[i] will combined together( i.e. 0.12 medium, 0.27 medium....) And my expected result is "0.12medium, 0.67 short and 0.98 high." How can I program it such that the computer know there have a three type of data, medium, short and high respectively. The question is so long!!! Thank you very much!!! :):):)

    P C 2 Replies Last reply
    0
    • W wong1907

      Hi, I am not good at programming. So, I hope somebody can help me to solve my problem. I already think it for a long time. My question is I have 2 set of datas. They are stored in variable no[i] and result[i]. no[0]=0.12 result[0]=medium no[1]=0.27 result[1]=medium no[2]=0.67 result[2]=short no[3]=0.43 result[3]=medium no[4]=0.98 result[4]=high no[i] and result[i] will combined together( i.e. 0.12 medium, 0.27 medium....) And my expected result is "0.12medium, 0.67 short and 0.98 high." How can I program it such that the computer know there have a three type of data, medium, short and high respectively. The question is so long!!! Thank you very much!!! :):):)

      P Offline
      P Offline
      Paul M Watt
      wrote on last edited by
      #2

      I would declare an enumeration in one of your header files that the "result" set can see the enumeration like this: enum {short = 1, medium = 2, long = 3}; Then you can use that code in your array. When you need to make your combined string or output, you will just need to decode a 1 to mean "short", 2 for "medium" and 3 for "high". Good Luck


      Build a man a fire, and he will be warm for a day
      Light a man on fire, and he will be warm for the rest of his life!

      1 Reply Last reply
      0
      • W wong1907

        Hi, I am not good at programming. So, I hope somebody can help me to solve my problem. I already think it for a long time. My question is I have 2 set of datas. They are stored in variable no[i] and result[i]. no[0]=0.12 result[0]=medium no[1]=0.27 result[1]=medium no[2]=0.67 result[2]=short no[3]=0.43 result[3]=medium no[4]=0.98 result[4]=high no[i] and result[i] will combined together( i.e. 0.12 medium, 0.27 medium....) And my expected result is "0.12medium, 0.67 short and 0.98 high." How can I program it such that the computer know there have a three type of data, medium, short and high respectively. The question is so long!!! Thank you very much!!! :):):)

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        As has been said, an enum is the obvious answer. The other thing is that if your two values are really one complex type, declare it as such with a struct. enum Result {short, medium, long}; // can use short = 0, medium =1, etc. with whatever values you want, but unless you use the values directly, it does not really matter what they are and they should be 0, 1, 2 by default. struct myType { float no; Result result; } Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups