Post by jNizM » 21 May 2019, 04:38
z.B.:
Code: Select all
SortArray(ListBoxArray := ["Birne", "Pflaume", "Apfel", "Traube", "Orange"])
for k, v in ListBoxArray
MeineListBox .= v "|"
Gui, Add, ListBox, w200 h100, % MeineListBox
Gui, Show, w300 h300
return
GuiClose:
ExitApp
SortArray(Array, Order := "A") ; https://sites.google.com/site/ahkref/custom-functions/sortarray
{
;Order A: Ascending, D: Descending, R: Reverse
MaxIndex := ObjMaxIndex(Array)
if (Order = "R") {
count := 0
loop % MaxIndex
ObjInsert(Array, ObjRemove(Array, MaxIndex - count++))
return
}
Partitions := "|" ObjMinIndex(Array) "," MaxIndex
loop {
comma := InStr(this_partition := SubStr(Partitions, InStr(Partitions, "|", False, 0)+1), ",")
spos := pivot := SubStr(this_partition, 1, comma-1) , epos := SubStr(this_partition, comma+1)
if (Order = "A") {
loop % epos - spos {
if (Array[pivot] > Array[A_Index+spos])
ObjInsert(Array, pivot++, ObjRemove(Array, A_Index+spos))
}
} else {
loop % epos - spos {
if (Array[pivot] < Array[A_Index+spos])
ObjInsert(Array, pivot++, ObjRemove(Array, A_Index+spos))
}
}
Partitions := SubStr(Partitions, 1, InStr(Partitions, "|", False, 0)-1)
if (pivot - spos) > 1 ;if more than one elements
Partitions .= "|" spos "," pivot-1 ;the left partition
if (epos - pivot) > 1 ;if more than one elements
Partitions .= "|" pivot+1 "," epos ;the right partition
} until !Partitions
}
z.B.:
[code]SortArray(ListBoxArray := ["Birne", "Pflaume", "Apfel", "Traube", "Orange"])
for k, v in ListBoxArray
MeineListBox .= v "|"
Gui, Add, ListBox, w200 h100, % MeineListBox
Gui, Show, w300 h300
return
GuiClose:
ExitApp
SortArray(Array, Order := "A") ; https://sites.google.com/site/ahkref/custom-functions/sortarray
{
;Order A: Ascending, D: Descending, R: Reverse
MaxIndex := ObjMaxIndex(Array)
if (Order = "R") {
count := 0
loop % MaxIndex
ObjInsert(Array, ObjRemove(Array, MaxIndex - count++))
return
}
Partitions := "|" ObjMinIndex(Array) "," MaxIndex
loop {
comma := InStr(this_partition := SubStr(Partitions, InStr(Partitions, "|", False, 0)+1), ",")
spos := pivot := SubStr(this_partition, 1, comma-1) , epos := SubStr(this_partition, comma+1)
if (Order = "A") {
loop % epos - spos {
if (Array[pivot] > Array[A_Index+spos])
ObjInsert(Array, pivot++, ObjRemove(Array, A_Index+spos))
}
} else {
loop % epos - spos {
if (Array[pivot] < Array[A_Index+spos])
ObjInsert(Array, pivot++, ObjRemove(Array, A_Index+spos))
}
}
Partitions := SubStr(Partitions, 1, InStr(Partitions, "|", False, 0)-1)
if (pivot - spos) > 1 ;if more than one elements
Partitions .= "|" spos "," pivot-1 ;the left partition
if (epos - pivot) > 1 ;if more than one elements
Partitions .= "|" pivot+1 "," epos ;the right partition
} until !Partitions
}[/code]