惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 【当耐特】
Help Net Security
Help Net Security
P
Proofpoint News Feed
J
Java Code Geeks
爱范儿
爱范儿
Last Week in AI
Last Week in AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Full Disclosure
Google DeepMind News
Google DeepMind News
H
Help Net Security
G
Google Developers Blog
Jina AI
Jina AI
Vercel News
Vercel News
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
Lohrmann on Cybersecurity
S
Schneier on Security
Microsoft Azure Blog
Microsoft Azure Blog
IT之家
IT之家
Security Archives - TechRepublic
Security Archives - TechRepublic
阮一峰的网络日志
阮一峰的网络日志
N
News and Events Feed by Topic
GbyAI
GbyAI
B
Blog
O
OpenAI News
博客园_首页
Cisco Talos Blog
Cisco Talos Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hacker News: Ask HN
Hacker News: Ask HN
TaoSecurity Blog
TaoSecurity Blog
腾讯CDC
MongoDB | Blog
MongoDB | Blog
M
MIT News - Artificial intelligence
C
Cybersecurity and Infrastructure Security Agency CISA
Cyberwarzone
Cyberwarzone
Webroot Blog
Webroot Blog
Simon Willison's Weblog
Simon Willison's Weblog
Y
Y Combinator Blog
C
Cisco Blogs
A
Arctic Wolf
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Exploit Database - CXSecurity.com
Security Latest
Security Latest
AI
AI
W
WeLiveSecurity
aimingoo的专栏
aimingoo的专栏
The Register - Security
The Register - Security
Project Zero
Project Zero
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
Netflix TechBlog - Medium
Blog — PlanetScale
Blog — PlanetScale

博客园 - 阿东hd

(转)Win32应用程序中进程间通信方法分析与比较 (转)程序间通信的各种途径及解析 (转)VB操作WORD搜集整理 - 阿东hd - 博客园 (转)资源 VBIDEFullScreen(全屏显示源码) (转)一篇好文,以在迷茫时阅读 vb datareport 换页 (转)深入剖析C#继承机制 (转)七个受用一生的心理寓言(强烈推荐) (备忘)vb根据文件完整路径获取文件名 - 阿东hd - 博客园 (求助)用傲游上csdn博客时标签栏和网址栏一直显示"袁萌" 的头像 - 阿东hd - 博客园 (转)评论:谁比微软更害怕“番茄花园”? (转)ASP.NET 常见参考项目的 UI、BLL 、Model 、 DAL 分析 (转)在.net中如何利用数据工厂实现多数据库的操作 (转)Microsoft .Net Remoting系列专题 (转)Crystal Report制作使用 (转)探索VB系列中的事件处理的奥秘 (转)VB程序错误处理方法小结 (转)VB的事件驱动是什么
快速排序算法 vb示例及分析
阿东hd · 2009-04-23 · via 博客园 - 阿东hd

快速排序对冒泡排序的一种改进。它的基本思想是:通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小,然后再按此方法对这两部分数据分别进行快速排序,整个排序过程可以递归进行,以此达到整个数据变成有序序列。

'快速排序算法,对字符串数组进行排序
Private Sub quicksort(ByRef arrValue() As String, ByVal intLx As Integer, ByVal intRx As Integer)
    'arrValue()是待排的数组,intLx,intRx为左右边界
    Dim strValue    As String
    Dim I           As Integer
    Dim j           As Integer
    Dim intLoop     As Integer
   
    I = intLx
    j = intRx
    Do
        While arrValue(I) <= arrValue(j) And I < j: I = I + 1: Wend
        If I < j Then
            strValue = arrValue(I)
            arrValue(I) = arrValue(j)
            arrValue(j) = strValue
           
           
            strValue = "1: i=" & CStr(I) & " j=" & CStr(j) & " "
            For intLoop = 0 To UBound(arrValue)
                strValue = strValue & " " & arrValue(intLoop)
            Next
            Debug.Print strValue
        End If
        While arrValue(I) <= arrValue(j) And I < j: j = j - 1: Wend
        If I < j Then
            strValue = arrValue(I)
            arrValue(I) = arrValue(j)
            arrValue(j) = strValue
           
            strValue = "2: i=" & CStr(I) & " j=" & CStr(j) & " "
            For intLoop = 0 To UBound(arrValue)
                strValue = strValue & " " & arrValue(intLoop)
            Next
            Debug.Print strValue

        End If
    Loop Until I = j
    I = I - 1: j = j + 1
   
    Debug.Print vbCrLf

    If I > intLx Then
        Call quicksort(arrValue, intLx, I)
    End If
    If j < intRx Then
        Call quicksort(arrValue, j, intRx)
    End If
End Sub

Private Sub Form_Load()
    Dim arr(8) As String
   
    arr(0) = "r"
    arr(1) = "e"
    arr(2) = "a"
    arr(3) = "n"
    arr(4) = "b"
    arr(5) = "u"
    arr(6) = "c"
    arr(7) = "o"
    arr(8) = "f"
   
    Call quicksort(arr, 0, UBound(arr))
End Sub

快速排序过程中的数据变化列表如下所示。从中可以看到一共执行了5次递归方法。每次执行时都是通过循环将数组从中间分割成2半,大的在右边,小的在左边,然后再针对这2半分别调用下一次递归方法。

排序前:      r e a n b u c o f

1: i=0 j=8  f e a n b u c o r
2: i=0 j=6  c e a n b u f o r
1: i=3 j=6  c e a f b u n o r
2: i=3 j=4  c e a b f u n o r


1: i=0 j=3  b e a c f u n o r
2: i=0 j=2  a e b c f u n o r
1: i=1 j=2  a b e c f u n o r


1: i=2 j=3  a b c e f u n o r


1: i=5 j=8  a b c e f r n o u
2: i=5 j=7  a b c e f o n r u


1: i=5 j=6  a b c e f n o r u