![]() |
Sorting Data: Bubble Sort
Simple bubble sort algorithm used when sorting data from least to greatest or from greatest to least. Bubble sorting is one of the slowest algorithms for sorting data, but, it's good enough when you have to sort arrays with a small number of data.
Least to Greatest: PHP Code:
Greatest to Least: PHP Code:
|
Good example and all... but sort of unnecessary.
I'm almost 100% sure that Graal has a built-in command for sorting arrays. |
Quote:
' if (array[b+1] < array[b]) ' is only changing Nice script tho Gambet :) Here is maybe how I would do it :p PHP Code:
|
Yes, would be more efficient for you to combine the two into one function. I separated the two merely just to show how to do each, and yes, to do one or the other only requires a flip in the symbol.
Quote:
??? You mean sortascending() and sortdescending() for TGraalVars? |
Quote:
PHP Code:
|
Nice code :)
sortascending()/sortdescending() currently only sort strings, so it's not helping in all cases. You can also use sortbyvalue() but it is more made for sorting objects |
This is pretty useful. I have a tendency to do a lot of stuff the manual way too, because it makes it easier to insert or remove needed or unneeded actions in a function.
|
Yes, figured this would be useful to people.
Using the built-in commands/functions is always a nice thing, but it does you no good if you don't understand the concepts behind them (i.e how to do them the manual way and so forth). Quote:
Which is why it's always nice to learn how to do things the manual way, just in case you're in a situation where you will need to script a function manually :) |
| All times are GMT +2. The time now is 01:51 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.