sort function
Blitz3D Forums/Blitz3D Programming/sort function
| ||
hi, my mind is breackdown.. i can make a sort function... i want to sort car position acording to the lap time... how can i make a sort for car positions? For puesto = 1 To coches For car = 1 To coches If Pos(car) = 0 Then If tiempo(car) < mejor_tiempo Then best_time = car End If End If Next Pos(best_time) = puesto mejor_tiempo = tiempo(best_time) Next |
| ||
i answer to my self i found this... http://blitzbasic.com/Community/posts.php?topic=22592#235043 but i still don't understand :( |
| ||
hi there is a little bug in the code posted, fixed: in esence you find the first which is out of order (starting to look from back to top), and move all the rest down to put the first not in sequence in it's place (going up, so like a bubble tends to go up!). That is doing for all the membres if necesary. as in the post says, is not fast, it depends on how much "not ordered" were the elements. Juan |
| ||
http://en.wikipedia.org/wiki/Bubble_sort This algorithm is pretty easy to implement. |
| ||
There is a load of sort functions in the code archives. QuickSort is probably the best one to go for. BubbleSort is pretty slow but it may not matter in this instance. |