SortList / SortStructuredList for Pointerlists

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

SortList / SortStructuredList for Pointerlists

Post by Josh »

It would be helpful if we could sort a PointerList so that the ValueList does not have to be changed.

Code: Select all

EnableExplicit  

Structure MyStruc
  Int1.i
  Int2.i
EndStructure

NewList ValueList.MyStruc()
NewList *PointerList.MyStruc()

AddElement (ValueList()) : ValueList()\Int1 = 11 : ValueList()\Int2 = 21
AddElement (ValueList()) : ValueList()\Int1 = 12 : ValueList()\Int2 = 22
AddElement (ValueList()) : ValueList()\Int1 = 13 : ValueList()\Int2 = 23
AddElement (ValueList()) : ValueList()\Int1 = 14 : ValueList()\Int2 = 24
AddElement (ValueList()) : ValueList()\Int1 = 15 : ValueList()\Int2 = 25

ForEach ValueList()
  AddElement (*PointerList())
  *PointerList() = @ValueList()
Next


SortStructuredList (ValueList()   , #PB_Sort_Descending, OffsetOf (MyStruc\Int1), TypeOf (MyStruc\Int1))
SortStructuredList (*PointerList(), #PB_Sort_Descending, OffsetOf (MyStruc\Int1), TypeOf (MyStruc\Int1))
sorry for my bad english