sorting problem
-
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!!! :):):)
-
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!!! :):):)
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! -
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!!! :):):)
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