Hi, is there an easy/fast method to sort a chooser list (alas listbrowser has) alphabetically?
Or do I have to use AVL_AddNode() or some bubble_sort merge_sort of my "own" to chooser nodes/names.
On AMINET there are some c sources of sorting methods (http://aminet.net/dev/src/sort.lha)
THX
You will want a sort algorithm that works well with linked lists.
For good speed with large lists I recommend a merge sort algorithm. Bubble sort OTOH is really easy to implement but scales really badly with big lists (if your lists are short enough that it doesn't matter though then go for it).
I use a merge sort algorithm for sorting cache nodes in my libdiskio/diskio.library block cache implementation:
https://github.com/salass00/ntfs-3g/blob/master/libdiskio/mergesort.c
Will try to implement/create the bubble_sort (almost have it) and see how it performs, the list wont be too big (theme pointers drawer names), but who knows.
Thx will take a look at your merge_srot code (and if you don't mind i can use on my program).
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
Me again, managed to code the bubble_sort method/function (isn't perfect and sure it has bugs), seems to work fine. Suggestion are welcome :-)
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
Instead of swapping node names which necessitates allocating a temporary before, memory freeing/allocation and lots of copying (especially since you use CNA_CopyText) you should be reordering the nodes themselves. This will not only have a lot less overhead but will also make your function more generic and therefore more easily reusable for other purposes.
Also if you want to make your sort function really reusable for sorting all kinds of exec doubly linked lists I suggest adding a callback parameter of some kind that is used to compare nodes rather than hardcoding the comparison in the sort function.
THX, will re-adapt bubble_sort code then.
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
Not that I can help Jabirulo with his problem but IMHO sorting should be an inherent feature of all list-based classes. What drives me really really mad about BOOPSI is that it is supposed to be the highest-level Intuition API, yet if forces you to do the lowest-level kind of things. This must get some attention!
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
Here is a version of bubble sort that I quickly put together:
Unless I made some mistake it should be working.
The hook function takes the standard hook pointer and the pointers of the two nodes to compare and should return a negative, zero or positive value depending on if the first node is less than, equal to or greater than the second one.
@trixie
FWIW there has been for some time a feature request in bugzilla for adding a sort function for exec style doubly linked lists to "utility.library".
If no one else gets round to implementing it first I might just take care of it myself.
I usually do something like this, then I don't need to care about implementing my own sort algorithm:
@jabirulo
Here's my two cents to the discussion:
The outer
'while()'
loop moves forward through the list, whereas the inner'while()'
loop moves backwards through the list for as long as necessary.In worst case (full inverse) it will go backwards until it hits the limit of the list
'(Prev == NULL)'
, in which case you better simply inverse the list:Have fun!
Btw, don't forget to detach the list from the gadget before you meddle with its nodes and reattach it when you're done.
OldFart
@all
thx will try those sort functions provided.
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P