博客
关于我
数组排序系列(8)
阅读量:285 次
发布时间:2019-03-03

本文共 1060 字,大约阅读时间需要 3 分钟。

Sortedlist排序法

'System.Collections.Sortedlist’对象的所有元素自动进行排序。

Sub SortedList()    Dim aintData(1 To 10) As Variant    Dim i As Integer    Dim intLB As Integer    Dim intUB As Integer    Dim avntData(1 To 10) As Variant    Dim objSortedList As Object    intLB = LBound(aintData)    intUB = UBound(aintData)    For i = intLB To intUB        aintData(i) = Application.WorksheetFunction.RandBetween(1, 100)    Next i    Debug.Print "Original Data: " & Join(aintData, ",")    Set objSortedList = CreateObject("System.Collections.Sortedlist")    For i = intLB To intUB        objSortedList.Add aintData(i), aintData(i)    Next i    For i = intLB To intUB        avntData(i) = objSortedList.getkey(i - 1)    Next i    Debug.Print "After Sort: " & Join(avntData, ",")End Sub

运行代码结果如下。

Original Data: 72,8,53,2,38,51,39,63,77,33

After Sort: 2,8,33,38,39,51,53,63,72,77

代码解析:

第14行代码创建’System.Collections.Sortedlist’对象实例。
第15行到第17行代码将数组元素添加的Sortedlist,添加过程中Sortedlist对象自动对所有元素进行排序。


此示例代码实现的是升序排序,如需使用降序,那么只需要修改第19行代码如下。

avntData(i) = objSortedList.getkey(intUB - i)

相关文章链接:

转载地址:http://fbjl.baihongyu.com/

你可能感兴趣的文章
nginx+tomcat单个域名及多个域名配置
查看>>
Nginx+Tomcat实现动静分离
查看>>
nginx+Tomcat性能监控
查看>>
nginx+uwsgi+django
查看>>
nginx+vsftp搭建图片服务器
查看>>
Nginx-http-flv-module流媒体服务器搭建+模拟推流+flv.js在前端html和Vue中播放HTTP-FLV视频流
查看>>
nginx-vts + prometheus 监控nginx
查看>>
Nginx/Apache反向代理
查看>>
Nginx: 413 – Request Entity Too Large Error and Solution
查看>>
nginx: [emerg] getpwnam(“www”) failed 错误处理方法
查看>>
nginx: [emerg] the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:
查看>>
nginx: [error] open() “/usr/local/nginx/logs/nginx.pid“ failed (2: No such file or directory)
查看>>
nginx:Error ./configure: error: the HTTP rewrite module requires the PCRE library
查看>>
Nginx:objs/Makefile:432: recipe for target ‘objs/src/core/ngx_murmurhash.o‘解决方法
查看>>
nginxWebUI runCmd RCE漏洞复现
查看>>
nginx_rtmp
查看>>
Nginx、HAProxy、LVS
查看>>
nginx一些重要配置说明
查看>>
Nginx下配置codeigniter框架方法
查看>>
Nginx与Tengine安装和使用以及配置健康节点检测
查看>>