Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Smallest number problem

Author
Message
Enclosed
20
Years of Service
User Offline
Joined: 8th Jun 2004
Location: Colorado
Posted: 7th Sep 2004 04:01 Edited at: 7th Sep 2004 04:04
I have recently been assembling a 3d game engine with collision with 3d models and gravity when I encountered an evil problem. I am making a collision priority subroutine but in order to do this I need to be able to sort out numbers by value. For example if I had variables that equal:4,2,6,and 3 I would need them sorted from least to greatest like this:2,3,4,6. Is there a command for this or an easy snippet, or must I do lotsa if commands? All help is apreciated. Thx.

Edit: Actually I need it mostly to just return the smallest value, I dont need a list
Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 7th Sep 2004 04:37
You could use an array instead of variables to make testing easier. Also do you want to return the variable/array index if it is 0 or greater than 0. Also what if 2 or more have the same low value?

Something like this might help.

Just remove the comments and it will ignore values of 0.
There may be a better way but this is the first thing I thought of.

Emperor Baal
20
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 7th Sep 2004 04:56 Edited at: 7th Sep 2004 04:58
Here's a fast version of the bubblesort method:



replace test() with your array name. Parameters are:
Lo = lowest index number : hi = highest index number

This way you can sort different areas of your array



here's the example code:


it sorts a 5000 array in 230ms here

Login to post a reply

Server time is: 2024-11-27 08:52:12
Your offset time is: 2024-11-27 08:52:12