Advertisement
Searinox

Untitled

Jul 19th, 2020
2,603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'sort ELEMENTS of an array, descending (bubble-sort)
  2. '  call:  A(n)= array, F= 1st position, L= last position, D= descending order, S= string sort
  3. '  exit:  A(n)= sorted, descending, positions F thru L
  4. '  temp:  I= Incr, J= Incr, swapped%
  5. <bubbleSort> '
  6.     for I = F to L - 1
  7.         swapped% = 0
  8.         for J = F to L - I - 1
  9.             if S = 1 and uaRowsSort$(J + D) > uaRowsSort$(J + (D = 0)) then gosub <bubbleSortSwap>
  10.             if S = 0 and val(uaRowsSort$(J + D)) > val(uaRowsSort$(J + (D = 0))) then gosub <bubbleSortSwap>
  11.         next J
  12.         if swapped% = 0 then J = L - I - 1
  13.     next I
  14.     return
  15. <>
  16.  
  17. <bubbleSortSwap> '
  18.     'swapTmp% = uaRowsSort%(J)
  19.     'uaRowsSort%(J) = uaRowsSort%(J + 1)
  20.     'uaRowsSort%(J + 1) = swapTmp%
  21.  
  22.     swapTmp$ = uaRowsSort$(J)
  23.     uaRowsSort$(J) = uaRowsSort$(J + 1)
  24.     uaRowsSort$(J + 1) = swapTmp$
  25.  
  26.     swapTmp$ = uaRows$(J)
  27.     uaRows$(J) = uaRows$(J + 1)
  28.     uaRows$(J + 1) = swapTmp$
  29.     swapped% = 1
  30.     return
  31. <>
  32.  
  33. F = edmDone% + 1 : L = dmLnLen% + edmDone% : D = (uaSortAsc% = 0) : S = 1
  34. gosub <bubbleSort>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement