UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: kevin on January 31, 2008, 02:41:24 PM

Title: Bubble Sort Typed (Character) Array
Post by: kevin on January 31, 2008, 02:41:24 PM
  Bubble Sort Typed  (Character) Array

  This example sorts all of the characters stored in the Characters() array in order, based upon their width values.  For simplicity the function uses bubble sorting algorithm, which is not quick, but hopefully easier for you to decipher how the type swapping is implemented.  Which is the trick here. Now rather than copy the elements manually (copy all the fields), this routine accesses the array directly (via pointer) and simply swaps the pair of type handles.   This way,  the size (in bytes of each element) won't impact upon the speed on the swap.    


Other Sorting Examples

   QuickSort Typed Array (http://www.underwaredesign.com/forums/index.php?topic=3444.0)
   Radix Sort Array (http://www.underwaredesign.com/forums/index.php?topic=2882.0)
   Better Bubble Sorting (http://www.underwaredesign.com/forums/index.php?topic=159.0)



Download

    Attached