Fandom

Academic Publishing Wiki

Check sort/Visual Basic

< Check sort

693pages on
this wiki
Add New Page
Talk0 Share

Performance Analysis Edit

Visual Basic code Edit

(You will need to add a Command Button to the form to print out the list of sorted numbers.)

  1. Option Explicit
  2. '------ Check sort & Rapid sort -----
  3. 'Please use the following criteris to write Visual Basic
  4. 'programs for any of the sort routines you feel capable of
  5. 'eliminating duplicates in a list in addition to sorting the list:
  6. '1.) Total number of items sorted.
  7. '2.) Total primary array size to accommodate the sort.
  8. '3.) Total secondary array size to accommodate the sort.
  9. '4.) Total length of key.
  10. '5.) Total time for setup[1].
  11. '6.) Total time for sort[2].
  12. '--------------------------------------------------
  13. Dim a() As Long, b() As Long
  14. Dim i As Long, n As Long, j As Long, k As Long
  15. Dim start As Double, finish2 As Double, finish1 As Double
  16. Const one As Integer = 1
  17. Const zero As Integer = 0
  18. Const maxi As Long = 9999999
  19. Const topnum As Long = 9999999
  20. Const botnum As Long = one
  21. Private Sub Form_Load()
  22. '--- clear file --------------------
  23. Open "c:\checksort.txt" For Output As 1
  24. Print #1, ""
  25. Close 1
  26. '--------------------------------------
  27. For k = botnum To topnum Step topnum / 100
  28. start = Timer
  29. '--------- load the array ------------
  30. 'ReDim a(maxi), b(maxi)
  31. ReDim a(k), b(k)
  32. For i = botnum To k
  33. n = Int(k * Rnd) + botnum
  34. 'a(n) = a(n) + one '(Used in place of a(n) = one below to convert Check sort to Rapid sort)
  35. a(n) = one '(Check sort)
  36. Next
  37. '--------end setup start sort ------------------
  38. finish1 = Timer - start
  39. start = Timer
  40. j = 0
  41. '------------------------------------------------------------
  42. For n = botnum To k
  43. If a(n) > zero Then b(j) = n: j = j + one
  44. Next
  45. '------------------------------------------------------------
  46. finish2 = Timer - start
  47. '-------------------------------------------------
  48. Open "c:\checksort.txt" For Append As 1
  49. Print #1, k; Chr$(9); finish1; Chr$(9); finish2
  50. Close 1
  51. '------------------------------------------------------------
  52. DoEvents
  53. Next k
  54. '------------------------------------------------------------
  55. Debug.Print
  56. Debug.Print "RESULTS: (Check sort)"
  57. Debug.Print
  58. Debug.Print "1.) Total number of items sorted:...................... "; Format(j, " #,###,###,###")
  59. Debug.Print "2.) Total primary array size to accomodate the sort:... "; Format(maxi, " #,###,###,###")
  60. Debug.Print "3.) Total secondary array size to accomodate the sort:. "; Format(j, " #,###,###,###")
  61. Debug.Print "4.) Total length of key:............................... "; Len(Str$(k)) - one; " decimal digits."
  62. Debug.Print "5.) Total time for setup:.............................. "; finish1; " seconds."
  63. Debug.Print "6.) Total time for sort:............................... "; finish2; " seconds."
  64. Debug.Print "7.) Ratio of Total sort time to setup time............. "; finish2/finish1; " percent."
  65. Debug.Print
  66. Debug.Print
  67. Form1.Show
  68. End
  69. End Sub
  70. Private Sub Command1_Click() '(requires command button)
  71. For i = one To j
  72. Debug.Print i; b(i)
  73. Next
  74. End Sub

noteEdit

  1. Time for setup refers to the time required to index the array variables with input data and increment the indexed variable's contents.
  2. Time for sort refers to the time required to parse the array, i.e., sequentially list or print indexes of variables with non-zero values.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.