Greatest to least
How can I get my program to order int variables greates to least. I have an array called "shade[6]". Each element of the array is an integer. I need my program to understand how to order the elements greatest to least so I can do things in a certain order.
I need help! Thanks!
make another array
then do loops to check if(shade[j]>shade[k]) where i goes through 0-5 before j increases by one. when the greatest one is found "newarray[0]=shade[?]" then do the whole loop again without the greatest one
well you get the idea, i hope. in return for doing the homework for you, i have assigned you yet another homework Convert my pseudo into c++!!
note im not a very good programmer myself so if you find my solution to be not very effective, well, paH!
edit: the "square bracket, i, close square bracket" after shade turned most of my post to italics, so i fixed to k
[edited by - tyro on August 19, 2002 9:30:03 PM]
then do loops to check if(shade[j]>shade[k]) where i goes through 0-5 before j increases by one. when the greatest one is found "newarray[0]=shade[?]" then do the whole loop again without the greatest one
well you get the idea, i hope. in return for doing the homework for you, i have assigned you yet another homework Convert my pseudo into c++!!
note im not a very good programmer myself so if you find my solution to be not very effective, well, paH!
edit: the "square bracket, i, close square bracket" after shade turned most of my post to italics, so i fixed to k
[edited by - tyro on August 19, 2002 9:30:03 PM]
No, this is not a homework question. If you really must know I need to be able to calculate which faces are drawn first and which are drawn last in a 3D engine. I know that faces with a a high shade[] value must be drawn first, then the rest in order. If this is not done, shapes look really weird; faces in the back of a model are drawn in the front... you can imagine how dumb it looks.
Can anyone help me? I've tried a few things already, but they either didn't work or would become way too bulky if the array index were to increase.
[edited by - Jackysan on August 19, 2002 9:37:16 PM]
Can anyone help me? I've tried a few things already, but they either didn't work or would become way too bulky if the array index were to increase.
[edited by - Jackysan on August 19, 2002 9:37:16 PM]
well we know its not a homework assigned by anybody but to ask questions like that is equivalent to asking somebody to do things like homework for you. The question that you ask asks somebody to solve a problem for you instead of doing it yourself, this fourm is for beginers to be helped out in difficult situations by more experienced programers, not for beginers to ask experienced programmers to do stuff for them
I guess this sounds kind of rude, but I don''t mean it as a flame...
How can you expect to be doing 3D programming if you can''t figure out a simple sort? Not only that, but it appears you can''t even use google (web or usenet) search, which would turn up thousands if not millions of hits on sorting algorithms.
However, to avoid being completely off-topic here, look into the qsort function.
How can you expect to be doing 3D programming if you can''t figure out a simple sort? Not only that, but it appears you can''t even use google (web or usenet) search, which would turn up thousands if not millions of hits on sorting algorithms.
However, to avoid being completely off-topic here, look into the qsort function.
Well, first off, I'm sorry if I appeared angry or something (I didn't know my little red faced icon would spark such emotion) and I can see why messing with a 3D engine seems a little above what I'm looking for.
You're right too, I should have tried google (I usually do all the time, but I also like to post things on forums before I search, just incase nothing shows up to solve my problem).
Like I said, I'm not trying to be angry or mean, but just because I can get the algorithms for 3D graphics doesn't mean I can find other algorithms just as easily, it really makes no difference.
Anyway, I'll try google, that's a good idea. Thanks!
P.S. It really isn't that "simple sort". Try to think of how to do that for an array with an index hovering around 100 and then doing certain routines in that order all by yourself. It also has to be as compact as possible (except for the routines themselves). It's possible, but pretty difficult. ^_^
[edited by - Jackysan on August 19, 2002 9:58:44 PM]
You're right too, I should have tried google (I usually do all the time, but I also like to post things on forums before I search, just incase nothing shows up to solve my problem).
Like I said, I'm not trying to be angry or mean, but just because I can get the algorithms for 3D graphics doesn't mean I can find other algorithms just as easily, it really makes no difference.
Anyway, I'll try google, that's a good idea. Thanks!
P.S. It really isn't that "simple sort". Try to think of how to do that for an array with an index hovering around 100 and then doing certain routines in that order all by yourself. It also has to be as compact as possible (except for the routines themselves). It's possible, but pretty difficult. ^_^
[edited by - Jackysan on August 19, 2002 9:58:44 PM]
yes and you shouldnt ask people to do it for you
and who says your angry(?)
and who says your angry(?)
Sorting *is* pretty simple.
If you understand basic algorithms and recursion, most sort functions (even the ones used in the real world like quicksort) are very easy to understand. And even if you knew nothing about sorting, if you''re trying to program 3D games you should be able to come up with something like bubblesort (which sucks, but would be more than fast enough for 100 index arrays, which you''re talking about here) on your own.
My honest advice (other than looking into qsort) would be to spend a bit more time learning the basics before trying to build a 3D engine.
If you understand basic algorithms and recursion, most sort functions (even the ones used in the real world like quicksort) are very easy to understand. And even if you knew nothing about sorting, if you''re trying to program 3D games you should be able to come up with something like bubblesort (which sucks, but would be more than fast enough for 100 index arrays, which you''re talking about here) on your own.
My honest advice (other than looking into qsort) would be to spend a bit more time learning the basics before trying to build a 3D engine.
Jackysan:
There are some intro articles on sorting on this site; check in the Articles & Resources section. If you are interested in purchasing a book, I would recommend Sedgewick''s Algorithms in C++ . It covers a lot of the basic stuff, including a couple of chapters on sorting algorithms.
John.
There are some intro articles on sorting on this site; check in the Articles & Resources section. If you are interested in purchasing a book, I would recommend Sedgewick''s Algorithms in C++ . It covers a lot of the basic stuff, including a couple of chapters on sorting algorithms.
John.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement