|
SortArray | |||
SortArray Array(), StartElement, EndElement | |||
Parameters: Array() = The Array you wish to sort StartElement = Starting element of range you wish sort EndElement = End element of the range you wish to sort |
|||
Returns: NONE | |||
SortArray will sort an array of Integer / Float values or Strings into ascending (alphabetical) order. The StartElement and EndElement let us control what section of the array is sorted. So you don't need to sort the entire thing each time. FACTS: * SortArray only supports Integer, Float & String arrays. Type arrays are not currently supported. * SortArray Only supports 1D arrays. * Values will be sorted into ascending order. (lowest to highest) * Strings will be sorted into alphabetical. (A-Z) - Case Is not important, so a string aabb and AABB would have equal sort precedence * SortArray uses the none comparative custom algorithm we call 'freq sorting' . This method gives very good results on [integer / float and string arrays. Older editions of PlayBASIC uses to use Quick Sort, but this much quicker. Mini Tutorial #1: This example with create an Integer Array, then fill it full random values, sort the array and then display the contents. [code] ; Create an Array... Dim Table(10) ; Fill theTable() Array with random values between 0 and 100. For lp =0 to 10 Table(lp)=rnd(100) next ; Display the array before it's sorted. Print "The Array Before Being Sorted" For lp =0 to 10 print Table(lp) next ; Sort the table array into ascending order using SortArray. ; This will sort the elements between array index 0 and ; array index 10. SortArray Table(),0,10 ; Display the sorted table() array Print "The Array After It's Been Sorted" For lp =0 to 10 print Table(lp) next ; Show the Display and wait for a key press Sync Waitkey [/code] The output of this code should look something like this. (although the table will be filled with random values each time.. So i'll just make up the values for the sake of this example.) The values before the array is sorted.
The array values after being sorted.
Mini Tutorial #2: In this example we're creating a array of names and using SortArray to sort them into alphabetical order.
|
|||
Example Source: Download This Example
|
Related Info: | CopyArray | CopyArrayCells | Dim | SearchHighestArrayCell | SearchLowestArrayCell : |
|
|||||||||||||||||||||||||||||||||||||||
(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com |