![]() |
|
Quick Sort for variable length strings - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Utilities (https://qb64phoenix.com/forum/forumdisplay.php?fid=8) +---- Thread: Quick Sort for variable length strings (/showthread.php?tid=4523) |
Quick Sort for variable length strings - bplus - 03-10-2026 Here is Quick Sort versus Comb Demo with 1000000 randomly chosen "words" <<< this means they aren't actually all words you can find in a dictionary, they are made randomly from this: b$ = b$ + Mid$("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.?", (Rnd * 64) \ 1 + 1, 1)) Code: (Select All) Option _ExplicitTo use Quick Sort include the Sub in your code, of course, then call QuickSort Lbound(array$), UBound(array$), array$() PS you can sort parts of the array as well, just use lowest place, to highest place but who does that? Simple as that! @PhilOfPerth RE: Quick Sort for variable length strings - SMcNeill - 03-10-2026 My only hesitation with QuickSort is its recursive. With the wrong lists and data, it’ll blow the stack and kill your program. CombSort is a little slower, but fast enough for most jobs, without any concerns for the stack. RE: Quick Sort for variable length strings - bplus - 03-10-2026 OK then there are 2 routines one can use! ![]() if you blow the stack try the other. I have never blown the stack but I am not serious data or computer science guy. RE: Quick Sort for variable length strings - SMcNeill - 03-10-2026 Code: (Select All) Quick Sort time: .364000000001397Both are doing this million sort in less than a second, which I find more than sufficient for the vast majority of my needs. Either is a good go-to for folks to just plug into their source. QuickSort is generally faster, unless the data is already well sorted and CombSort triggers that swap=0 early exit after just a few quick passes. I just personally find the comb sort to be less dangerous (no recursion or stack limits), and I've worked with it enough over the years that I can tweak it for any use case almost instantly. As always, folks just need to use whatever works best for them. As long as *you're* happy with the compiled result, it's a good result.
|