[Implemented] SortLinkedList()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Shopro
Enthusiast
Enthusiast
Posts: 148
Joined: Tue May 13, 2003 8:05 am

[Implemented] SortLinkedList()

Post by Shopro »

I am trying to code something that would sort a LinkedList structure, and I figured a command like this would be very handy:)

-Shopro
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

I have to definately agree, such as sort by a certain structure's member?
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Would be a very nice feature!
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

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 :D :D :D 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 :D
Shopro
Enthusiast
Enthusiast
Posts: 148
Joined: Tue May 13, 2003 8:05 am

Post by Shopro »

This is what I did:

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
it doesn't work as it is, so pls don't try to run it :o

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)
and it sorts automatically! Where do these "#LBS_SORT"s come from? and is the same thing possible in a ListIcon???

Anyone?!

-Shopro
horst
Enthusiast
Enthusiast
Posts: 197
Joined: Wed May 28, 2003 6:57 am
Location: Munich
Contact:

Post by horst »

Horst.
Shopro
Enthusiast
Enthusiast
Posts: 148
Joined: Tue May 13, 2003 8:05 am

Post by Shopro »

horst:
YES! This is exactly what I wanted!!

I will use your library in my project, thank you:)!

-Shopro
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

@Horst

Rahh lovely :D :D
Your QLsort procedure rox !!
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Post by dontmailme »

I just found a need for this and I can report that it still rocks with 4.10b2 :D

Nice work!
Paid up PB User !
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

So you don't want to use SortStructuredList()?
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

it seems to be a case of RTFM.... :lol:
oh... and have a nice day.
Heathen
Enthusiast
Enthusiast
Posts: 498
Joined: Tue Sep 27, 2005 6:54 pm
Location: At my pc coding..

Post by Heathen »

Kaeru Gaman wrote:it seems to be a case of RTFM.... :lol:
:lol:
I love Purebasic.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

For sure, it's definitely a case of Reorganize/Filter The Memory!
BERESHEIT
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

netmaestro wrote:For sure, it's definitely a case of Reorganize/Filter The Memory!
RFTM <> RTFM!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Sorry, my dylsexia is showing thru
BERESHEIT
Post Reply