home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / sorts2 / sorts.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  21.8 KB  |  789 lines

  1. VERSION 2.00
  2. Begin Form Sorts 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "A Program of Sorts"
  6.    ClientHeight    =   5250
  7.    ClientLeft      =   1095
  8.    ClientTop       =   1425
  9.    ClientWidth     =   6690
  10.    FontBold        =   -1  'True
  11.    FontItalic      =   0   'False
  12.    FontName        =   "MS Sans Serif"
  13.    FontSize        =   9.75
  14.    FontStrikethru  =   0   'False
  15.    FontUnderline   =   0   'False
  16.    ForeColor       =   &H00FFFFFF&
  17.    Height          =   5655
  18.    Icon            =   SORTS.FRX:0000
  19.    Left            =   1035
  20.    LinkMode        =   1  'Source
  21.    LinkTopic       =   "Form1"
  22.    MaxButton       =   0   'False
  23.    MinButton       =   0   'False
  24.    ScaleHeight     =   5250
  25.    ScaleWidth      =   6690
  26.    Top             =   1080
  27.    Width           =   6810
  28.    Begin CommandButton EXIT_PGM 
  29.       Caption         =   "EXIT"
  30.       Enabled         =   0   'False
  31.       Height          =   855
  32.       Left            =   5580
  33.       TabIndex        =   7
  34.       Top             =   240
  35.       Width           =   855
  36.    End
  37.    Begin CommandButton START 
  38.       Caption         =   "START"
  39.       Height          =   855
  40.       Left            =   4500
  41.       TabIndex        =   6
  42.       Top             =   240
  43.       Width           =   855
  44.    End
  45.    Begin PictureBox SortPlot 
  46.       BackColor       =   &H00FFFFFF&
  47.       DrawWidth       =   3
  48.       ForeColor       =   &H00000000&
  49.       Height          =   3996
  50.       Left            =   240
  51.       ScaleHeight     =   3960
  52.       ScaleWidth      =   3960
  53.       TabIndex        =   0
  54.       Top             =   240
  55.       Width           =   3996
  56.    End
  57.    Begin Label Label5 
  58.       Alignment       =   2  'Center
  59.       BackColor       =   &H00C0C0C0&
  60.       Caption         =   "EXIT leaves program, writes result file."
  61.       Height          =   435
  62.       Left            =   4440
  63.       TabIndex        =   11
  64.       Top             =   1200
  65.       Width           =   2055
  66.    End
  67.    Begin Label Label4 
  68.       Alignment       =   2  'Center
  69.       BackColor       =   &H00C0C0C0&
  70.       Caption         =   "Results text file will be placed in C:\SORT_LST.TXT"
  71.       ForeColor       =   &H00FF0000&
  72.       Height          =   615
  73.       Left            =   4440
  74.       TabIndex        =   10
  75.       Top             =   1920
  76.       Width           =   2055
  77.    End
  78.    Begin Label Label1 
  79.       Alignment       =   2  'Center
  80.       BackColor       =   &H00C0C0C0&
  81.       Caption         =   "Algorithm Run Time"
  82.       Height          =   255
  83.       Left            =   4440
  84.       TabIndex        =   9
  85.       Top             =   2700
  86.       Width           =   2055
  87.    End
  88.    Begin Label text1 
  89.       Alignment       =   2  'Center
  90.       BackColor       =   &H0000FFFF&
  91.       Caption         =   "Algorithm   Now Running   Shown on Title Bar"
  92.       FontBold        =   -1  'True
  93.       FontItalic      =   0   'False
  94.       FontName        =   "MS Sans Serif"
  95.       FontSize        =   12
  96.       FontStrikethru  =   0   'False
  97.       FontUnderline   =   0   'False
  98.       Height          =   1275
  99.       Left            =   4560
  100.       TabIndex        =   8
  101.       Top             =   3780
  102.       Visible         =   0   'False
  103.       Width           =   1815
  104.    End
  105.    Begin Label Clock 
  106.       Alignment       =   2  'Center
  107.       BackColor       =   &H00C0C0C0&
  108.       Caption         =   "00:00.00"
  109.       FontBold        =   -1  'True
  110.       FontItalic      =   0   'False
  111.       FontName        =   "Arial"
  112.       FontSize        =   18
  113.       FontStrikethru  =   0   'False
  114.       FontUnderline   =   0   'False
  115.       ForeColor       =   &H00000000&
  116.       Height          =   435
  117.       Left            =   4440
  118.       TabIndex        =   5
  119.       Top             =   3000
  120.       Width           =   2055
  121.    End
  122.    Begin Label Swaps 
  123.       Alignment       =   2  'Center
  124.       BackColor       =   &H00C0C0C0&
  125.       Caption         =   "XXX"
  126.       FontBold        =   -1  'True
  127.       FontItalic      =   0   'False
  128.       FontName        =   "Arial"
  129.       FontSize        =   13.5
  130.       FontStrikethru  =   0   'False
  131.       FontUnderline   =   0   'False
  132.       ForeColor       =   &H00000000&
  133.       Height          =   315
  134.       Left            =   2700
  135.       TabIndex        =   4
  136.       Top             =   4680
  137.       Width           =   975
  138.    End
  139.    Begin Label Iterations 
  140.       Alignment       =   2  'Center
  141.       BackColor       =   &H00C0C0C0&
  142.       Caption         =   "XXX"
  143.       FontBold        =   -1  'True
  144.       FontItalic      =   0   'False
  145.       FontName        =   "Arial"
  146.       FontSize        =   13.5
  147.       FontStrikethru  =   0   'False
  148.       FontUnderline   =   0   'False
  149.       ForeColor       =   &H00000000&
  150.       Height          =   315
  151.       Left            =   780
  152.       TabIndex        =   3
  153.       Top             =   4680
  154.       Width           =   975
  155.    End
  156.    Begin Label Label3 
  157.       Alignment       =   2  'Center
  158.       BackColor       =   &H00C0C0C0&
  159.       Caption         =   "Swaps"
  160.       FontBold        =   -1  'True
  161.       FontItalic      =   0   'False
  162.       FontName        =   "Arial"
  163.       FontSize        =   9.75
  164.       FontStrikethru  =   0   'False
  165.       FontUnderline   =   0   'False
  166.       ForeColor       =   &H00000000&
  167.       Height          =   255
  168.       Left            =   2700
  169.       TabIndex        =   2
  170.       Top             =   4320
  171.       Width           =   975
  172.    End
  173.    Begin Label Label2 
  174.       Alignment       =   2  'Center
  175.       BackColor       =   &H00C0C0C0&
  176.       Caption         =   "Iterations"
  177.       FontBold        =   -1  'True
  178.       FontItalic      =   0   'False
  179.       FontName        =   "Arial"
  180.       FontSize        =   9.75
  181.       FontStrikethru  =   0   'False
  182.       FontUnderline   =   0   'False
  183.       ForeColor       =   &H00000000&
  184.       Height          =   255
  185.       Left            =   780
  186.       TabIndex        =   1
  187.       Top             =   4320
  188.       Width           =   975
  189.    End
  190. Dim unit(100) As Integer
  191. Dim StartTime As Double
  192. Dim oldx1 As Integer, oldy1 As Integer, oldx2 As Integer, oldy2 As Integer
  193. Dim newx1 As Integer, newy1 As Integer, newx2 As Integer, newy2 As Integer
  194. Dim Done As Integer, DisplayOn As Integer
  195. Dim comp As Integer, swic As Integer
  196. Dim p(100) As Integer, w(100) As Integer
  197. Dim results(3, 8) As String
  198. Dim base_data(100) As Integer
  199. Dim first_pass As Integer
  200. Sub bsort ()
  201.     StartTime = Now
  202.     Dim j As Integer, k As Integer, l As Integer, t As Integer
  203.     For l = 1 To 100
  204.         j = l
  205.         For k = j + 1 To 100
  206.             comp = comp + 1
  207.             If unit(k) <= unit(j) Then
  208.                 j = k
  209.                 q% = DoEvents()
  210.             End If
  211.         Next k
  212.         If l <> j Then
  213.             swic = swic + 1
  214.             t = unit(j)
  215.             oldx1 = unit(j)
  216.             oldy1 = j
  217.             unit(j) = unit(l)
  218.             oldx2 = unit(l)
  219.             oldy2 = l
  220.             newx1 = unit(j)
  221.             newy1 = j
  222.             unit(l) = t
  223.             newx2 = unit(l)
  224.             newy2 = l
  225.             ShowTime
  226.             ShowIter
  227.             OverPlot
  228.             NewPlot
  229.                 q% = DoEvents()
  230.         End If
  231.     Next l
  232.     ShowTime
  233.     ShowIter
  234. End Sub
  235. Sub dfsort ()
  236.     Dim cl As Integer, cr As Integer, k As Integer
  237.     Dim min As Integer, max As Integer, umin As Integer, umax As Integer, t As Integer
  238.     StartTime = Now
  239.     For cl = 1 To 50
  240.         cr = 101 - cl
  241.         max = unit(cr)
  242.         umax = cr
  243.         min = unit(cl)
  244.         umin = cl
  245.                 q% = DoEvents()
  246.         For k = cr To cl Step -1
  247.             comp = comp + 1
  248.                 q% = DoEvents()
  249.             If unit(k) < min Then
  250.                 min = unit(k)
  251.                 umin = k
  252.             End If
  253.         Next k
  254.                 
  255.         If unit(cl) > unit(umin) Then
  256.             swic = swic + 1
  257.             t = unit(cl)
  258.             oldx1 = unit(cl)
  259.             oldy1 = cl
  260.             unit(cl) = unit(umin)
  261.             newx1 = unit(cl)
  262.             newy1 = cl
  263.             oldx2 = unit(umin)
  264.             oldy2 = umin
  265.             unit(umin) = t
  266.             newx2 = unit(umin)
  267.             newy2 = umin
  268.             ShowTime
  269.             ShowIter
  270.             OverPlot
  271.             NewPlot
  272.                 q% = DoEvents()
  273.         End If
  274.         
  275.         For k = cl To cr
  276.             comp = comp + 1
  277.                 q% = DoEvents()
  278.             If unit(k) > max Then
  279.                 max = unit(k)
  280.                 umax = k
  281.             End If
  282.                 q% = DoEvents()
  283.         Next k
  284.         
  285.         If unit(umax) > unit(cr) Then
  286.             swic = swic + 1
  287.             t = unit(cr)
  288.             oldx1 = unit(cr)
  289.             oldy1 = cr
  290.             unit(cr) = unit(umax)
  291.             newx1 = unit(cr)
  292.             newy1 = cr
  293.             oldx2 = unit(umax)
  294.             oldy2 = umax
  295.             unit(umax) = t
  296.             newx2 = unit(umax)
  297.             newy2 = umax
  298.             ShowTime
  299.             ShowIter
  300.             OverPlot
  301.             NewPlot
  302.                 q% = DoEvents()
  303.         End If
  304.     Next cl
  305.     ShowTime
  306.     ShowIter
  307. End Sub
  308. Sub EXIT_PGM_Click ()
  309. Unload sorts
  310. End Sub
  311. Sub Form_Load ()
  312.     Screen.MousePointer = 11
  313.     Randomize
  314.     SortPlot.Scale (1, 1)-(100, 100)
  315.     sorts.Refresh
  316.     RackEmUp
  317.     ShowPlots
  318.     DisplayOn = True
  319.     Screen.MousePointer = 0
  320.     first_pass = False
  321. End Sub
  322. Sub Form_Unload (Cancel As Integer)
  323. Open "c:\sort_lst.txt" For Output As #1
  324. Print #1, "Sort"; Chr$(9); "Time"; Chr$(9); "Iterations"; Chr$(9); "Swaps"; Chr$(13); Chr$(10)
  325. For x = 1 To 8
  326.     Print #1, results(0, x); Chr$(9); results(1, x); Chr$(9); results(2, x); Chr$(9); results(3, x); Chr$(13); Chr$(10)
  327. Next x
  328. Close #1
  329. End Sub
  330. Sub gksort ()
  331.     StartTime = Now
  332.     SortStep = 100
  333.     SortTemp = SortStep
  334.     Swap = True
  335.     Do While SortStep > 0 And Swap
  336.         Swap = False
  337.         For RangeEnd = SortStep To 100 Step SortStep
  338.             For RangeStart = RangeEnd - SortStep To RangeEnd - 1 Step SortStep
  339.                 If RangeEnd + SortStep > 100 Then RangeEnd = 100
  340.                     For i% = 0 To (RangeEnd - RangeStart) \ 2
  341.                         If unit(i% + RangeStart) > unit(RangeEnd - i%) Then
  342.                             swic = swic + 1
  343.                             Swap = True
  344.                             t = unit(i% + RangeStart)
  345.                             oldx1 = unit(i% + RangeStart)
  346.                             oldy1 = i% + RangeStart
  347.                             unit(i% + RangeStart) = unit(RangeEnd - i%)
  348.                             newx1 = unit(i% + RangeStart)
  349.                             newy1 = i% + RangeStart
  350.                             oldx2 = unit(RangeEnd - i%)
  351.                             oldy2 = RangeEnd - i%
  352.                             unit(RangeEnd - i%) = t
  353.                             newx2 = unit(RangeEnd - i%)
  354.                             newy2 = RangeEnd - i%
  355.                             ShowTime
  356.                             ShowIter
  357.                             OverPlot
  358.                             NewPlot
  359.                         End If
  360.                         comp = comp + 1
  361.                     Next i%
  362.             Next RangeStart
  363.         Next RangeEnd
  364.         If Not Swap Then
  365.             x = 100 \ SortStep
  366.             x = x + 1
  367.             SortStep = 100 \ x
  368.             If SortStep = SortTemp Then
  369.                 SortStep = SortStep - 1
  370.             End If
  371.             SortTemp = SortStep
  372.             Swap = True
  373.         End If
  374.     Loop
  375.     ShowTime
  376.     ShowIter
  377. End Sub
  378. Sub HeapSort_Click ()
  379. If Done = True Then resetplot
  380. hsort
  381. End Sub
  382. Sub hsort ()
  383.     StartTime = Now
  384.     For i = 1 To 100
  385.         j = i
  386.         k = 0
  387.         Do While unit(i) <> i And j <= 100
  388.                 q% = DoEvents()
  389.             j = j + 1
  390.             comp = comp + 1
  391.             If unit(unit(i)) <> unit(i) Then
  392.                 q% = DoEvents()
  393.                 swic = swic + 1
  394.                 t = unit(unit(i))
  395.                 oldx1 = unit(unit(i))
  396.                 oldy1 = unit(i)
  397.                 unit(unit(i)) = unit(i)
  398.                 newx1 = unit(unit(i))
  399.                 newy1 = unit(i)
  400.                 oldx2 = unit(i)
  401.                 oldy2 = i
  402.                 unit(i) = t
  403.                 newx2 = unit(i)
  404.                 newy2 = i
  405.                 ShowTime
  406.                 ShowIter
  407.                 OverPlot
  408.                 NewPlot
  409.             End If
  410.                 q% = DoEvents()
  411.         Loop
  412.     Next i
  413.     ShowTime
  414.     ShowIter
  415.     selsort
  416. End Sub
  417. Sub isort ()
  418.     Dim i As Integer, j As Integer, v As Integer
  419.     StartTime = Now
  420.     n = 100
  421.     For j = 2 To n
  422.                 q% = DoEvents()
  423.         v = unit(j)
  424.         oldx1 = unit(j)
  425.         oldy1 = j
  426.         i = j - 1
  427.         comp = comp + 1
  428.         While v < unit(i)
  429.                 q% = DoEvents()
  430.             swic = swic + 1
  431.             unit(i + 1) = unit(i)
  432.             oldx2 = unit(i)
  433.             oldy2 = i
  434.             newx2 = unit(i + 1)
  435.             newy2 = i + 1
  436.             ShowTime
  437.             ShowIter
  438.             OverPlot2
  439.             NewPlot2
  440.             i = i - 1
  441.         Wend
  442.                 q% = DoEvents()
  443.         swic = swic + 1
  444.         unit(i + 1) = v
  445.         newx1 = unit(i + 1)
  446.         newy1 = i + 1
  447.         ShowTime
  448.         ShowIter
  449.         OverPlot1
  450.         NewPlot1
  451.     Next j
  452.     ShowTime
  453.     ShowIter
  454. End Sub
  455. Sub NewPlot ()
  456. SortPlot.PSet (newx1, newy1), QBColor(0)
  457. SortPlot.PSet (newx2, newy2), QBColor(0)
  458. 'SortPlot.PSet (newx1, newy1), QBColor(11)
  459. 'SortPlot.PSet (newx2, newy2), QBColor(11)
  460. End Sub
  461. Sub NewPlot1 ()
  462. SortPlot.PSet (newx1, newy1), QBColor(0)
  463. 'SortPlot.PSet (newx1, newy1), QBColor(11)
  464. End Sub
  465. Sub NewPlot2 ()
  466. SortPlot.PSet (newx2, newy2), QBColor(0)
  467. 'SortPlot.PSet (newx2, newy2), QBColor(11)
  468. End Sub
  469. Sub OverPlot ()
  470. SortPlot.PSet (oldx1, oldy1), QBColor(15)
  471. SortPlot.PSet (oldx2, oldy2), QBColor(15)
  472. End Sub
  473. Sub OverPlot1 ()
  474. SortPlot.PSet (oldx1, oldy1), QBColor(15)
  475. End Sub
  476. Sub OverPlot2 ()
  477.     SortPlot.PSet (oldx2, oldy2), QBColor(15)
  478. End Sub
  479. Sub qsort ()
  480.     Dim i As Integer, j As Integer, b As Integer, l As Integer, t As Integer, r As Integer, d As Integer
  481.     StartTime = Now
  482.     k = 1
  483.     p(k) = 1
  484.     w(k) = 100
  485.     l = 1
  486.     d = 1
  487.     r = 100
  488.     Do
  489. toploop:
  490.                 q% = DoEvents()
  491.         If r - l < 9 Then GoTo bubsort
  492.                 q% = DoEvents()
  493.         i = l
  494.         j = r
  495.         While j > i
  496.             comp = comp + 1
  497.                 q% = DoEvents()
  498.             If unit(i) > unit(j) Then
  499.                 q% = DoEvents()
  500.                 swic = swic + 1
  501.                 t = unit(j)
  502.                 oldx1 = unit(j)
  503.                 oldy1 = j
  504.                 unit(j) = unit(i)
  505.                 oldx2 = unit(i)
  506.                 oldy2 = i
  507.                 newx1 = unit(j)
  508.                 newy1 = j
  509.                 unit(i) = t
  510.                 newx2 = unit(i)
  511.                 newy2 = i
  512.                 OverPlot
  513.                 NewPlot
  514.                 ShowTime
  515.                 ShowIter
  516.                 d = -d
  517.             End If
  518.             If d = -1 Then
  519.                 j = j - 1
  520.                 q% = DoEvents()
  521.             Else
  522.                 i = i + 1
  523.                 q% = DoEvents()
  524.             End If
  525.         Wend
  526.         j = j + 1
  527.         k = k + 1
  528.                 q% = DoEvents()
  529.         If i - l < r - j Then
  530.             p(k) = j
  531.             w(k) = r
  532.             r = i
  533.                 q% = DoEvents()
  534.         Else
  535.             p(k) = l
  536.             w(k) = i
  537.             l = j
  538.                 q% = DoEvents()
  539.         End If
  540.         d = -d
  541.                 q% = DoEvents()
  542.         GoTo toploop
  543. bubsort:
  544.         If r - l > 0 Then
  545.                 q% = DoEvents()
  546.             For i = l To r
  547.                 b = i
  548.                 q% = DoEvents()
  549.                 For j = b + 1 To r
  550.                     comp = comp + 1
  551.                     If unit(j) <= unit(b) Then b = j
  552.                 q% = DoEvents()
  553.                 Next j
  554.                 If i <> b Then
  555.                 q% = DoEvents()
  556.                     swic = swic + 1
  557.                     t = unit(b)
  558.                     oldx1 = unit(b)
  559.                     oldy1 = b
  560.                     unit(b) = unit(i)
  561.                     oldx2 = unit(i)
  562.                     oldy2 = i
  563.                     newx1 = unit(b)
  564.                     newy1 = b
  565.                     unit(i) = t
  566.                     newx2 = unit(i)
  567.                     newy2 = i
  568.                     OverPlot
  569.                     NewPlot
  570.                     ShowTime
  571.                     ShowIter
  572.                 End If
  573.             Next i
  574.         End If
  575.         l = p(k)
  576.         r = w(k)
  577.         k = k - 1
  578.                 q% = DoEvents()
  579.     Loop Until k = 0
  580.     ShowTime
  581.     ShowIter
  582. End Sub
  583. Sub RackEmUp ()
  584. If first_pass = False Then
  585.     For cell = 1 To 100
  586. MakeCell:
  587.         vl = Int(Rnd(1) * 100) + 1
  588.         'For chk = 1 To cell - 1
  589.             'If vl = unit(chk) Then GoTo MakeCell
  590.         'Next chk
  591.         unit(cell) = vl
  592.         base_data(cell) = vl
  593.     Next cell
  594.     first_pass = True
  595.     For x = 1 To 100
  596.         unit(x) = base_data(x)
  597.     Next x
  598. End If
  599. End Sub
  600. Sub RadixSort_Click ()
  601. If Done = True Then resetplot
  602. rsort
  603. End Sub
  604. Sub resetplot ()
  605.     Screen.MousePointer = 11
  606.     SortPlot.Line (1, 1)-(100, 100), QBColor(0), BF
  607.     SortPlot.Refresh
  608.     comp = 0
  609.     swic = 0
  610.     RackEmUp
  611.     ShowPlots
  612.     Screen.MousePointer = 0
  613. End Sub
  614. Sub rsort ()
  615. End Sub
  616. Sub selsort ()
  617.     Dim i As Integer, j As Integer, t As Integer, n As Integer
  618.     StartTime = Now
  619.     n = 100
  620.     For i = 1 To n - 1
  621.         q% = DoEvents()
  622.         For j = i + 1 To n
  623.         q% = DoEvents()
  624.             comp = comp + 1
  625.             If unit(j) < unit(i) Then
  626.         q% = DoEvents()
  627.                 swic = swic + 1
  628.                 t = unit(i)
  629.                 oldx1 = unit(i)
  630.                 oldy1 = i
  631.                 unit(i) = unit(j)
  632.                 newx1 = unit(i)
  633.                 newy1 = i
  634.                 oldx2 = unit(j)
  635.                 oldy2 = j
  636.                 unit(j) = t
  637.                 newx2 = unit(j)
  638.                 newy2 = j
  639.                 ShowTime
  640.                 ShowIter
  641.                 OverPlot
  642.                 NewPlot
  643.             End If
  644.         q% = DoEvents()
  645.         Next j
  646.         q% = DoEvents()
  647.     Next i
  648.     ShowTime
  649.     ShowIter
  650. End Sub
  651. Sub ShowIter ()
  652.     iterations.Caption = LTrim$(Str$(comp))
  653.     iterations.Refresh
  654.     swaps.Caption = LTrim$(Str$(swic))
  655.     swaps.Refresh
  656. End Sub
  657. Sub ShowPlots ()
  658.     For lin = 1 To 100
  659.         SortPlot.PSet (unit(lin), lin), QBColor(0)
  660.     Next lin
  661. End Sub
  662. Sub ShowTime ()
  663.     elapsed# = Now - StartTime
  664.     tim$ = Format$(elapsed#, "hh:mm:ss")
  665.     clock.Caption = tim$
  666.     clock.Refresh
  667. End Sub
  668. Sub ssort ()
  669.     Dim m As Integer, j As Integer, i As Integer, t As Integer
  670.     StartTime = Now
  671.     m = 100
  672.     While m > 0
  673.                 q% = DoEvents()
  674.         m = m \ 2
  675.         For i = m To 99
  676.                 q% = DoEvents()
  677.             For j = (i - m + 1) To 1 Step -m
  678.                 comp = comp + 1
  679.                 q% = DoEvents()
  680.                 If unit(j) <= unit(j + m) Then Exit For
  681.                 q% = DoEvents()
  682.                 swic = swic + 1
  683.                 t = unit(j)
  684.                 oldx1 = unit(j)
  685.                 oldy1 = j
  686.                 unit(j) = unit(j + m)
  687.                 newx1 = unit(j)
  688.                 newy1 = j
  689.                 oldx2 = unit(j + m)
  690.                 oldy2 = j + m
  691.                 unit(j + m) = t
  692.                 newx2 = unit(j + m)
  693.                 newy2 = j + m
  694.                 ShowTime
  695.                 ShowIter
  696.                 OverPlot
  697.                 NewPlot
  698.             Next j
  699.         Next i
  700.     Wend
  701.     ShowTime
  702.     ShowIter
  703. End Sub
  704. Sub START_Click ()
  705. text1.Visible = True
  706. start.Enabled = False
  707. exit_pgm.Enabled = True
  708. sorts.Caption = "Bubble Sort"
  709. resetplot
  710. Refresh
  711. bsort
  712. results(0, 1) = "Bubble sort"
  713. results(1, 1) = Str$(time_gone())
  714. results(2, 1) = iterations.Caption
  715. results(3, 1) = swaps.Caption
  716. sorts.Caption = "DF Sort"
  717. resetplot
  718. Refresh
  719. dfsort
  720. results(0, 2) = "DF Sort"
  721. results(1, 2) = Str$(time_gone())
  722. results(2, 2) = iterations.Caption
  723. results(3, 2) = swaps.Caption
  724. sorts.Caption = "GK Sort"
  725. resetplot
  726. Refresh
  727. gksort
  728. results(0, 3) = "GK Sort"
  729. results(1, 3) = Str$(time_gone())
  730. results(2, 3) = iterations.Caption
  731. results(3, 3) = swaps.Caption
  732. sorts.Caption = "Heap Sort"
  733. resetplot
  734. Refresh
  735. hsort
  736. results(0, 4) = "Heap Sort"
  737. results(1, 4) = Str$(time_gone())
  738. results(2, 4) = iterations.Caption
  739. results(3, 4) = swaps.Caption
  740. sorts.Caption = "Insertion Sort"
  741. resetplot
  742. Refresh
  743. isort
  744. results(0, 5) = "Insertion Sort"
  745. results(1, 5) = Str$(time_gone())
  746. results(2, 5) = iterations.Caption
  747. results(3, 5) = swaps.Caption
  748. sorts.Caption = "Quick Sort"
  749. resetplot
  750. Refresh
  751. qsort
  752. results(0, 6) = "Quick Sort"
  753. results(1, 6) = Str$(time_gone())
  754. results(2, 6) = iterations.Caption
  755. results(3, 6) = swaps.Caption
  756. sorts.Caption = "Selective Sort"
  757. resetplot
  758. Refresh
  759. selsort
  760. results(0, 7) = "Selective Sort"
  761. results(1, 7) = Str$(time_gone())
  762. results(2, 7) = iterations.Caption
  763. results(3, 7) = swaps.Caption
  764. sorts.Caption = "Shell Sort"
  765. resetplot
  766. Refresh
  767. ssort
  768. results(0, 8) = "Shell Sort"
  769. results(1, 8) = Str$(time_gone())
  770. results(2, 8) = iterations.Caption
  771. results(3, 8) = swaps.Caption
  772. text1.Visible = False
  773. start.Enabled = True
  774. exit_pgm.Enabled = False
  775. End Sub
  776. Sub SubPlot ()
  777.     SortPlot.PSet (subx, suby), QBColor(13)
  778. End Sub
  779. Function time_gone ()
  780. q$ = clock.Caption
  781. hours = Val(Left$(q$, 2))
  782. minutes = Val(Mid$(q$, 4, 2))
  783. seconds = Val(Right$(q$, 2))
  784. time_gone = seconds + (minutes * 60) + (hours * 360)
  785. End Function
  786. Sub UnSubPlot ()
  787.     SortPlot.PSet (unsubx, unsuby), QBColor(11)
  788. End Sub
  789.