[Implemented] SortLinkedList()
[Implemented] SortLinkedList()
I am trying to code something that would sort a LinkedList structure, and I figured a command like this would be very handy:)
-Shopro
-Shopro
I knew I saw this somewhere, below are two different links, I havent tried them yet. However, one allows you to have a linklist in another linklist (usefull for custom GUI), and another is a sorted link list by a structure member
Im looking to combine the two, as that is what I need.
Sorted Link List: http://www.reelmedia.org/pb/modules.php ... it&lid=127
Linklist in Linklist: http://www.reelmedia.org/pb/modules.php ... it&lid=195
Turns out the link-list in a link-list is worthless for us purists
Those of us who are looking for cross-platform code. As it uses the WinAPI. however, the author did state that the WinAPI will be replaced when PB's memory library is usable 



Sorted Link List: http://www.reelmedia.org/pb/modules.php ... it&lid=127
Linklist in Linklist: http://www.reelmedia.org/pb/modules.php ... it&lid=195
Turns out the link-list in a link-list is worthless for us purists


This is what I did:
it doesn't work as it is, so pls don't try to run it
Shannara: yes, to be able to sort by a certain structure's member
After coding the above, I looked at the Code Archives, and found a "ListBox Sort.pb". With this code...
and it sorts automatically! Where do these "#LBS_SORT"s come from? and is the same thing possible in a ListIcon???
Anyone?!
-Shopro
Code: Select all
;- Sort Linked List
;
Procedure Toppings_Sort()
Protected Sort_MaxElements.l
Protected Sort_NumberOfTimesSorted.l
Protected Sort_CurrentElement.l
Protected Sort_FirstElementToCompare.w, Sort_FirstElementToCompare45Pointer.l
Protected Sort_SecondElementToCompare.w, Sort_SecondElementToComparePointer.l
Protected Sort_SizeOfToppingStructure.l
Flag_ToppingsEdited = #True
Structure_Topping_Temp.Structure_Topping
Sort_SizeOfToppingStructure = SizeOf(Structure_Topping)
Sort_MaxElements = CountList(List_Structure_Topping())
For Sort_NumberOfTimesSorted = 0 To Sort_MaxElements
ResetList(List_Structure_Topping())
For Sort_CurrentElement = 1 To Sort_MaxElements - Sort_NumberOfTimesSorted - 1
NextElement(List_Structure_Topping())
Sort_FirstElementToCompare = Asc(UCase(Left(List_Structure_Topping()\Name$, 1)))
Sort_FirstElementToComparePointer = @List_Structure_Topping()
NextElement(List_Structure_Topping())
Sort_SecondElementToCompare = Asc(UCase(Left(List_Structure_Topping()\Name$, 1)))
Sort_SecondElementToComparePointer = @List_Structure_Topping()
If Sort_FirstElementToCompare > Sort_SecondElementToCompare
CopyMemory(Sort_FirstElementToComparePointer, @Structure_Topping_Temp, Sort_SizeOfToppingStructure)
CopyMemory(Sort_SecondElementToComparePointer, Sort_FirstElementToComparePointer, Sort_SizeOfToppingStructure)
CopyMemory(@Structure_Topping_Temp, Sort_SecondElementToComparePointer, Sort_SizeOfToppingStructure)
EndIf
PreviousElement(List_Structure_Topping())
Next
Next
EndProcedure

Shannara: yes, to be able to sort by a certain structure's member
After coding the above, I looked at the Code Archives, and found a "ListBox Sort.pb". With this code...
Code: Select all
ListViewGadget(1, 10,10,280,280,#LBS_SORT | #LBS_NOINTEGRALHEIGHT | #LBS_HASSTRINGS)
Anyone?!
-Shopro
-
- Enthusiast
- Posts: 537
- Joined: Wed Oct 29, 2003 10:35 am
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada