久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2467|回復: 0
打印 上一主題 下一主題
收起左側

VB6 排序算法

[復制鏈接]
跳轉到指定樓層
樓主
ID:94349 發表于 2015-11-2 14:27 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
  1. Attribute VB_Name = "Module1"
  2. Option Explicit
  3. Global Const ZERO = 0
  4. Global Const ASCENDING_ORDER = 0
  5. Global Const DESCENDING_ORDER = 1

  6. Global gIterations
  7. '
  8. Sub BubbleSort(MyArray(), ByVal nOrder As Integer)
  9. Dim Index
  10. Dim TEMP
  11. Dim NextElement

  12.     NextElement = ZERO
  13.     Do While (NextElement < UBound(MyArray))
  14.         Index = UBound(MyArray)
  15.         Do While (Index > NextElement)
  16.             If nOrder = ASCENDING_ORDER Then
  17.                 If MyArray(Index) < MyArray(Index - 1) Then
  18.                     TEMP = MyArray(Index)
  19.                     MyArray(Index) = MyArray(Index - 1)
  20.                     MyArray(Index - 1) = TEMP
  21.                 End If
  22.             ElseIf nOrder = DESCENDING_ORDER Then
  23.                 If MyArray(Index) >= MyArray(Index - 1) Then
  24.                     TEMP = MyArray(Index)
  25.                     MyArray(Index) = MyArray(Index - 1)
  26.                     MyArray(Index - 1) = TEMP
  27.                 End If
  28.             End If
  29.             Index = Index - 1
  30.             gIterations = gIterations + 1
  31.         Loop
  32.         NextElement = NextElement + 1
  33.         gIterations = gIterations + 1
  34.     Loop

  35. End Sub

  36. Sub Bucket(MyArray(), ByVal nOrder As Integer)
  37. Dim Index
  38. Dim NextElement
  39. Dim TheBucket

  40.     NextElement = LBound(MyArray) + 1
  41.     While (NextElement <= UBound(MyArray))
  42.         TheBucket = MyArray(NextElement)
  43.         Index = NextElement
  44.         Do
  45.             If Index > LBound(MyArray) Then
  46.                 If nOrder = ASCENDING_ORDER Then
  47.                     If TheBucket < MyArray(Index - 1) Then
  48.                         MyArray(Index) = MyArray(Index - 1)
  49.                         Index = Index - 1
  50.                     Else
  51.                         Exit Do
  52.                     End If
  53.                 ElseIf nOrder = DESCENDING_ORDER Then
  54.                     If TheBucket >= MyArray(Index - 1) Then
  55.                         MyArray(Index) = MyArray(Index - 1)
  56.                         Index = Index - 1
  57.                     Else
  58.                         Exit Do
  59.                     End If
  60.                 End If
  61.             Else
  62.                 Exit Do
  63.             End If
  64.             gIterations = gIterations + 1
  65.         Loop
  66.         MyArray(Index) = TheBucket
  67.         NextElement = NextElement + 1
  68.         gIterations = gIterations + 1
  69.     Wend

  70. End Sub

  71. Sub Heap(MyArray())
  72. Dim Index
  73. Dim Size
  74. Dim TEMP

  75.     Size = UBound(MyArray)
  76.      
  77.     Index = 1
  78.     While (Index <= Size)
  79.         Call HeapSiftup(MyArray(), Index)
  80.         Index = Index + 1
  81.         gIterations = gIterations + 1
  82.     Wend

  83.     Index = Size
  84.     While (Index > 0)
  85.         TEMP = MyArray(0)
  86.         MyArray(0) = MyArray(Index)
  87.         MyArray(Index) = TEMP
  88.         Call HeapSiftdown(MyArray(), Index - 1)
  89.         Index = Index - 1
  90.         gIterations = gIterations + 1
  91.     Wend

  92. End Sub
  93.   

  94. Sub HeapSiftdown(MyArray(), M)
  95. Dim Index
  96. Dim Parent
  97. Dim TEMP

  98.     Index = 0
  99.     Parent = 2 * Index

  100.     Do While (Parent <= M)
  101.          
  102.         If (Parent < M And MyArray(Parent) < MyArray(Parent + 1)) Then
  103.             Parent = Parent + 1
  104.         End If

  105.         If MyArray(Index) >= MyArray(Parent) Then
  106.             Exit Do
  107.         End If

  108.         TEMP = MyArray(Index)
  109.         MyArray(Index) = MyArray(Parent)
  110.         MyArray(Parent) = TEMP
  111.          
  112.         Index = Parent
  113.         Parent = 2 * Index

  114.         gIterations = gIterations + 1
  115.     Loop
  116. End Sub

  117. Sub HeapSiftup(MyArray(), M)
  118. Dim Index
  119. Dim Parent
  120. Dim TEMP

  121.     Index = M
  122.     Do While (Index > 0)
  123.         Parent = Int(Index / 2)

  124.         If MyArray(Parent) >= MyArray(Index) Then
  125.             Exit Do
  126.         End If
  127.          
  128.         TEMP = MyArray(Index)
  129.         MyArray(Index) = MyArray(Parent)
  130.         MyArray(Parent) = TEMP

  131.         Index = Parent
  132.         gIterations = gIterations + 1
  133.     Loop
  134.      
  135. End Sub

  136. Sub Insertion(MyArray(), ByVal nOrder As Integer)
  137. Dim Index
  138. Dim TEMP
  139. Dim NextElement
  140.      
  141.     NextElement = LBound(MyArray) + 1
  142.     While (NextElement <= UBound(MyArray))
  143.         Index = NextElement
  144.         Do
  145.             If Index > LBound(MyArray) Then
  146.                 If nOrder = ASCENDING_ORDER Then
  147.                     If MyArray(Index) < MyArray(Index - 1) Then
  148.                         TEMP = MyArray(Index)
  149.                         MyArray(Index) = MyArray(Index - 1)
  150.                         MyArray(Index - 1) = TEMP
  151.                         Index = Index - 1
  152.                     Else
  153.                         Exit Do
  154.                     End If
  155.                 ElseIf nOrder = DESCENDING_ORDER Then
  156.                     If MyArray(Index) >= MyArray(Index - 1) Then
  157.                         TEMP = MyArray(Index)
  158.                         MyArray(Index) = MyArray(Index - 1)
  159.                         MyArray(Index - 1) = TEMP
  160.                         Index = Index - 1
  161.                     Else
  162.                         Exit Do
  163.                     End If
  164.                 End If
  165.             Else
  166.                 Exit Do
  167.             End If
  168.             gIterations = gIterations + 1
  169.         Loop
  170.         NextElement = NextElement + 1
  171.         gIterations = gIterations + 1
  172.     Wend

  173. End Sub

  174. Sub QuickSort(MyArray(), L, R)
  175. Dim I, J, X, Y

  176.     I = L
  177.     J = R
  178.     X = MyArray((L + R) / 2)
  179.          
  180.     While (I <= J)
  181.         While (MyArray(I) < X And I < R)
  182.             I = I + 1
  183.         Wend
  184.         While (X < MyArray(J) And J > L)
  185.             J = J - 1
  186.         Wend
  187.         If (I <= J) Then
  188.             Y = MyArray(I)
  189.             MyArray(I) = MyArray(J)
  190.             MyArray(J) = Y
  191.             I = I + 1
  192.             J = J - 1
  193.         End If
  194.         gIterations = gIterations + 1
  195.     Wend

  196.     If (L < J) Then Call QuickSort(MyArray(), L, J)
  197.     If (I < R) Then Call QuickSort(MyArray(), I, R)

  198. End Sub

  199. Sub Selection(MyArray(), ByVal nOrder As Integer)
  200. Dim Index
  201. Dim Min
  202. Dim NextElement
  203. Dim TEMP

  204.     NextElement = 0
  205.     While (NextElement < UBound(MyArray))
  206.         Min = UBound(MyArray)
  207.         Index = Min - 1
  208.         While (Index >= NextElement)
  209.             If nOrder = ASCENDING_ORDER Then
  210.                 If MyArray(Index) < MyArray(Min) Then
  211.                     Min = Index
  212.                 End If
  213.             ElseIf nOrder = DESCENDING_ORDER Then
  214.                 If MyArray(Index) >= MyArray(Min) Then
  215.                     Min = Index
  216.                 End If
  217.             End If
  218.             Index = Index - 1
  219.             gIterations = gIterations + 1
  220.         Wend
  221.         TEMP = MyArray(Min)
  222.         MyArray(Min) = MyArray(NextElement)
  223.         MyArray(NextElement) = TEMP
  224.         NextElement = NextElement + 1
  225.         gIterations = gIterations - 1
  226.     Wend

  227. End Sub

  228. Sub ShellSort(MyArray(), ByVal nOrder As Integer)
  229. Dim Distance
  230. Dim Size
  231. Dim Index
  232. Dim NextElement
  233. Dim TEMP

  234.     Size = UBound(MyArray) - LBound(MyArray) + 1
  235.     Distance = 1

  236.     While (Distance <= Size)
  237.         Distance = 2 * Distance
  238.     Wend

  239.     Distance = (Distance / 2) - 1
  240.      
  241.     While (Distance > 0)
  242.      
  243.         NextElement = LBound(MyArray) + Distance
  244.      
  245.         While (NextElement <= UBound(MyArray))
  246.             Index = NextElement
  247.             Do
  248.                 If Index >= (LBound(MyArray) + Distance) Then
  249.                     If nOrder = ASCENDING_ORDER Then
  250.                         If MyArray(Index) < MyArray(Index - Distance) Then
  251.                             TEMP = MyArray(Index)
  252.                             MyArray(Index) = MyArray(Index - Distance)
  253.                             MyArray(Index - Distance) = TEMP
  254.                             Index = Index - Distance
  255.                             gIterations = gIterations + 1
  256.                         Else
  257.                             Exit Do
  258.                         End If
  259.                     ElseIf nOrder = DESCENDING_ORDER Then
  260.                         If MyArray(Index) >= MyArray(Index - Distance) Then
  261.                             TEMP = MyArray(Index)
  262.                             MyArray(Index) = MyArray(Index - Distance)
  263.                             MyArray(Index - Distance) = TEMP
  264.                             Index = Index - Distance
  265.                             gIterations = gIterations + 1
  266.                         Else
  267.                             Exit Do
  268.                         End If
  269.                     End If
  270.                 Else
  271.                     Exit Do
  272.                 End If
  273.             Loop
  274.             NextElement = NextElement + 1
  275.             gIterations = gIterations + 1
  276.         Wend
  277.         Distance = (Distance - 1) / 2
  278.         gIterations = gIterations + 1
  279.     Wend
  280.      
  281. End Sub
復制代碼




分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 久久国产福利 | 伊人免费观看视频 | 男人天堂网站 | 九九热国产视频 | 天天躁日日躁狠狠的躁天龙影院 | 欧美性受 | 久久久久久久网 | 成人一区二区三区在线 | 亚洲有码转帖 | 日韩欧美三级电影 | 国产一区二区三区久久久久久久久 | 色综合久久久 | 麻豆av电影网| 99影视| 欧美成人精品激情在线观看 | 91在线免费视频 | 激情婷婷| 国产高清久久久 | 国户精品久久久久久久久久久不卡 | 91精品中文字幕一区二区三区 | 视频一区二区三区在线观看 | 亚洲国产91 | 欧美中国少妇xxx性高请视频 | 日韩一区二区在线视频 | 国产精品欧美一区喷水 | 日本精品一区二区三区视频 | 色综合国产 | 欧美爱爱视频网站 | 日韩和的一区二在线 | 一区二区三区视频 | 亚洲一区中文字幕 | 日本五月婷婷 | 一区二区视频 | 精品国产18久久久久久二百 | 在线国产视频 | 国产欧美一区二区精品久导航 | 国产精品视频导航 | 国内自拍视频在线观看 | 免费午夜视频 | 特黄色毛片 | 欧美日韩精品久久久免费观看 |