Difference between revisions of "LlListSort"
Jump to navigation
Jump to search
m (lsl code tagging) |
m |
||
Line 11: | Line 11: | ||
The sort order is affected by type.<br/> | The sort order is affected by type.<br/> | ||
Each type is sorted individually and then feathered to have the same order of types. | Each type is sorted individually and then feathered to have the same order of types. | ||
< | <lsl>llListSort([1, "C", 3, "A", 2, "B"], 1, TRUE) returns [1, "A", 2, "B", 3, "C"] | ||
llListSort([1, 3, 2, "C", "A", "B"], 1, TRUE) | llListSort([1, 3, 2, "C", "A", "B"], 1, TRUE) returns [1, 2, 3, "A", "B", "C"] | ||
llListSort([1, "C", 3, "A", 2, "B"], 2, TRUE) | llListSort([1, "C", 3, "A", 2, "B"], 2, TRUE) returns [1, "C", 2, "B", 3, "A"]</lsl> | ||
|caveats=A bubble sort is a sorting algorithm with a Big O of N*N. Why Linden Labs did not use a N*log(N) sorting algorithm such as [http://en.wikipedia.org/wiki/Heapsort Heap Sort] or [http://en.wikipedia.org/wiki/Mergesort Merge Sort] is unkown... | |caveats=A bubble sort is a sorting algorithm with a Big O of N*N. Why Linden Labs did not use a N*log(N) sorting algorithm such as [http://en.wikipedia.org/wiki/Heapsort Heap Sort] or [http://en.wikipedia.org/wiki/Mergesort Merge Sort] is unkown... | ||
|constants | |constants |
Revision as of 15:53, 4 May 2008
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Summary
Function: list llListSort( list src, integer stride, integer ascending );0.0 | Forced Delay |
10.0 | Energy |
Returns a list that is src sorted by stride.
• list | src | – | List to be sorted. | |
• integer | stride | – | number of entries per stride, if less then 1 it is assumed to be 1. | |
• integer | ascending | – | if FALSE then the sort order is descending, otherwise the order is ascending. |
Specification
A slow bubble sort is employed to perform the sort.
The sort order is affected by type.
Each type is sorted individually and then feathered to have the same order of types.
<lsl>llListSort([1, "C", 3, "A", 2, "B"], 1, TRUE) returns [1, "A", 2, "B", 3, "C"]
llListSort([1, 3, 2, "C", "A", "B"], 1, TRUE) returns [1, 2, 3, "A", "B", "C"]
llListSort([1, "C", 3, "A", 2, "B"], 2, TRUE) returns [1, "C", 2, "B", 3, "A"]</lsl>
Caveats
A bubble sort is a sorting algorithm with a Big O of N*N. Why Linden Labs did not use a N*log(N) sorting algorithm such as Heap Sort or Merge Sort is unkown...
Examples
<lsl> list numbers = [3, "three", 2, "two", 1, "one"]; default {
state_entry() { llOwnerSay(llDumpList2String(numbers, ",")); // Object: 3,three,2,two,1,one numbers = llListSort(numbers, 2, TRUE); llOwnerSay(llDumpList2String(numbers, ",")); // Object: 1,one,2,two,3,three }
}
</lsl>