Results 1 to 7 of 7

Thread: Sorting arrays with built-in sorting functions

  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Sorting arrays with built-in sorting functions

    Sorting numeric arrays?
    Using built-in sorting functions it can take ... no time.


     '---Globals
     DIM MaxCount     AS LONG value 100000
     dim MyArray(MaxCount) as long
     dim Count      as long
     dim T1, T2      as double
     DIM Message     AS STRING
    
     '---Ask if execute or not
     Message = "This program will fill an array of " & MaxCount & " elements with random LONG numbers.\n"
     Message += "Array will be sorted twice in order to test sorting of sparse and already sorted array.\n\n"
     Message += "Please press Yes to go on, NO to Stop\n"
     DIM lResult AS LONG = MSGBOX(0, Message, %MB_YESNO, "Continue?")
     IF lResult <> %IDYES THEN
      STOP
     END IF
    
     '---Speed up operations a bit
     doevents(off)
    
     '---Init random number generator
     randomize
     
     '---Fill array with random numbers
     T1 = GetTickCount
     for Count = LBound(MyArray) To UBound(MyArray) 
      MyArray(Count) = rnd(-1000000000, 1000000000) 
     next 
     T2 = GetTickCount
    
    
     '---Do the job
     msgbox 0, _
         "Time to fill randomly an array of " & ubound(MyArray) & " elements:" & $tab & format$(T2-T1) & " mSecs" & $crlf & _
         "Time to sort array "               & repeat$(5, $tab) & testsort(MyArray)     & " mSecs" & $crlf & _
         "Time to re-sort sorted array "          & repeat$(4, $tab) & testsort(MyArray)     & " mSecs" & $crlf & _
         "Time to re-sort sorted array in descending order " & repeat$(2, $tab) & testsort(MyArray, %TRUE) & " mSecs" & $crlf & _
         ""
    
     '----------------------------------------------------------------------------
     '---In case you want to see some output values, just uncomment those lines
     '----------------------------------------------------------------------------
     'uses "console"
     'for count = 1 to 80
     ' console_write MyArray(Count) & ", "
     'next
     'console_waitkey 
     
     '----------------------------------------------------------------------------
     '---Sorting function
     '----------------------------------------------------------------------------
     Function TestSort(byref v() as long, optional DeScendSorting as long) as long
      
      '---Time measuring vars
      local ticka, tickb as double
      
      '---Start timer
      ticka = GetTickCount
      
      '---Sort array passed by reference depending on sort order
      if DeScendSorting = %TRUE then
       array sort v, descend
      else
       array sort v
      end if
    
      '---ENd timer
      tickb = GetTickCount
      function = tickb - ticka 
      
     End Function
    
    Last edited by ErosOlmi; 21-02-2024 at 21:35.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  2. #2
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: Sorting arrays with built-in sorting functions

    Awesome we need these kind of samples Eros, thanks so much. You might want to talk with Roberto, he had an interesting idea of placing all of these in a repository so easy to find.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Sorting arrays with built-in sorting functions

    Repository is already there at http://scripts.thinbasic.com/ but abandoned.
    I did it almost one year ago but at that time it was not the right time.

    I will consider your wiki suggestion checking which is the best around.
    I want it easy to be used and with syntax highlight.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: Sorting arrays with built-in sorting functions

    Bookmarked, never saw it or don't remember that. I would sticky that to the top or put in the menubar on the forums for sure. Great!!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Sorting arrays with built-in sorting functions

    Ken,

    we are not maintaining it anymore.
    I will delete it and substitute with a new one after choosing the best we can find.
    So continue your suggestion about wiki. I will follow it and in the meantime try to find what will be better for thinBasic community.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #6
    Have you considered using a wiki for maintaining and sharing these code samples for the thinBasic community, as suggested by kryton9?

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Quote Originally Posted by Limaxdum View Post
    Have you considered using a wiki for maintaining and sharing these code samples for the thinBasic community, as suggested by kryton9?
    Those messages posted by AI bot are doing great job
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. 3d arrays?
    By JosephE in forum thinDebug
    Replies: 2
    Last Post: 08-08-2010, 23:21
  2. Arrays
    By Charles Pegge in forum O2h Compiler
    Replies: 0
    Last Post: 17-03-2009, 16:09

Members who have read this thread: 4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •