30. 使用LotusScript排序

2024-02-01 18:58
文章标签 使用 排序 30 lotusscript

本文主要是介绍30. 使用LotusScript排序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

排序是计算机编程中最常见的任务之一,排序算法也是最基本和常用的算法。存在许多种排序算法,它们的效率和复杂性各不相同。在LotusNotes中,公式语言里有@Sort函数,对List排序。LotusScript里没有类似的可以用作容器的数据结构,也就没有提供针对它们的排序功能。另外,使用LotusScript开发时,主要的数据对象是NotesDocument,而它们的排序都已经在视图里完成了,所以需要排序的情况并不多。但是有时候,我们也会遇到排序的需求,比如针对列表字段里的多值或是没有存在于文档中的数据。这时就需要我们在LotusScript里实现排序算法。这并不是特别困难的事,不过如果你想省事(像我一样),也可以使用现成的代码,比如下面的这几个用于排序的函数就来自于LotusNotes自带的模版数据库:

Public Function QuickSort(sArray As Variant) As VariantDim sA() As String    Dim j As LongDim bottom As LongDim top As LongDim vA As Variantbottom = LBound ( sArray )top = UBound ( sArray )ReDim sA( bottom To top ) As String     For j = bottom To topsA ( j ) = sArray ( j )Next' DoQS does a QuickSort if the Sublist is longer than 10 elements' Thus, when DoQS finishes, all elements are within 10 spots of their correct location.' For lists that are close to being in order, an Insertion Sort is much faster than a QuickSort, so we' run through the whole thing once doing an Insertion Sort to finish tidying up the order.Call DoQS( sA, bottom, top )Call DoInsertSort ( sA, bottom, top )ReDim vA(bottom To top) As VariantFor j = bottom To topvA ( j ) = sA ( j )Next	QuickSort = vA
End Function
Sub DoInsertSort ( sA() As String, ByVal bottom As Long, ByVal top As Long )	Dim i As LongDim x As LongDim v As StringDim Found As IntegerFor i = bottom+1 To topx = iv = sA (i )Do While (sA(x-1) > v)sA ( x ) = sA ( x-1 )x = x - 1If x=0 ThenExit DoEnd IfLoopsA (x) = vNext
End Sub
Sub DoQS( sA() As String, bottom As Long, top As Long )' Called by QuickSortDim length As LongDim i As LongDim j As LongDim Pivot As LongDim PivotValue As StringDim t As StringDim LastSmall As Longlength = top - bottom + 1' Only do the QuickSort if the sublist is at least 10 items longIf length > 10 Then' Pivot is chosen approx. halfway through sublist.' This gives us best speed if list is almost sorted already, and is no worse than any' other choice if the list is in random order.Pivot = bottom + (length \ 2)   ' Move PivotValue out of the wayPivotValue = sA( Pivot )sA ( Pivot ) = sA ( bottom )sA ( bottom ) = PivotValue' LastSmall is the location of the last value smaller than PivotValueLastSmall = bottomFor i = bottom + 1 To top If sA ( i ) < PivotValue Then LastSmall = LastSmall + 1t = sA ( i )sA ( i ) = sA ( LastSmall )sA ( LastSmall ) = tEnd IfNext' Move the PivotValue backt = sA ( LastSmall )sA ( LastSmall ) = sA ( bottom )sA ( bottom ) = tPivot = LastSmall' Now sort each sideCall DoQS ( sA, bottom, Pivot - 1 )Call DoQS ( sA, Pivot + 1, top )End IfEnd Sub

只需要调用QuickSort函数,它会对参数中的数组排序然后返回。它根据数组的大小采用快速排序和插入排序两种不同的算法。

这篇关于30. 使用LotusScript排序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/668163

相关文章

Java function函数式接口的使用方法与实例

《Javafunction函数式接口的使用方法与实例》:本文主要介绍Javafunction函数式接口的使用方法与实例,函数式接口如一支未完成的诗篇,用Lambda表达式作韵脚,将代码的机械美感... 目录引言-当代码遇见诗性一、函数式接口的生物学解构1.1 函数式接口的基因密码1.2 六大核心接口的形态学

使用DeepSeek API 结合VSCode提升开发效率

《使用DeepSeekAPI结合VSCode提升开发效率》:本文主要介绍DeepSeekAPI与VisualStudioCode(VSCode)结合使用,以提升软件开发效率,具有一定的参考价值... 目录引言准备工作安装必要的 VSCode 扩展配置 DeepSeek API1. 创建 API 请求文件2.

使用TomCat,service输出台出现乱码的解决

《使用TomCat,service输出台出现乱码的解决》本文介绍了解决Tomcat服务输出台中文乱码问题的两种方法,第一种方法是修改`logging.properties`文件中的`prefix`和`... 目录使用TomCat,service输出台出现乱码问题1解决方案问题2解决方案总结使用TomCat,

解决IDEA使用springBoot创建项目,lombok标注实体类后编译无报错,但是运行时报错问题

《解决IDEA使用springBoot创建项目,lombok标注实体类后编译无报错,但是运行时报错问题》文章详细描述了在使用lombok的@Data注解标注实体类时遇到编译无误但运行时报错的问题,分析... 目录问题分析问题解决方案步骤一步骤二步骤三总结问题使用lombok注解@Data标注实体类,编译时

Java中使用Java Mail实现邮件服务功能示例

《Java中使用JavaMail实现邮件服务功能示例》:本文主要介绍Java中使用JavaMail实现邮件服务功能的相关资料,文章还提供了一个发送邮件的示例代码,包括创建参数类、邮件类和执行结... 目录前言一、历史背景二编程、pom依赖三、API说明(一)Session (会话)(二)Message编程客

C++中使用vector存储并遍历数据的基本步骤

《C++中使用vector存储并遍历数据的基本步骤》C++标准模板库(STL)提供了多种容器类型,包括顺序容器、关联容器、无序关联容器和容器适配器,每种容器都有其特定的用途和特性,:本文主要介绍C... 目录(1)容器及简要描述‌php顺序容器‌‌关联容器‌‌无序关联容器‌(基于哈希表):‌容器适配器‌:(

使用Python实现高效的端口扫描器

《使用Python实现高效的端口扫描器》在网络安全领域,端口扫描是一项基本而重要的技能,通过端口扫描,可以发现目标主机上开放的服务和端口,这对于安全评估、渗透测试等有着不可忽视的作用,本文将介绍如何使... 目录1. 端口扫描的基本原理2. 使用python实现端口扫描2.1 安装必要的库2.2 编写端口扫

使用Python实现操作mongodb详解

《使用Python实现操作mongodb详解》这篇文章主要为大家详细介绍了使用Python实现操作mongodb的相关知识,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、示例二、常用指令三、遇到的问题一、示例from pymongo import MongoClientf

SQL Server使用SELECT INTO实现表备份的代码示例

《SQLServer使用SELECTINTO实现表备份的代码示例》在数据库管理过程中,有时我们需要对表进行备份,以防数据丢失或修改错误,在SQLServer中,可以使用SELECTINT... 在数据库管理过程中,有时我们需要对表进行备份,以防数据丢失或修改错误。在 SQL Server 中,可以使用 SE

使用Python合并 Excel单元格指定行列或单元格范围

《使用Python合并Excel单元格指定行列或单元格范围》合并Excel单元格是Excel数据处理和表格设计中的一项常用操作,本文将介绍如何通过Python合并Excel中的指定行列或单... 目录python Excel库安装Python合并Excel 中的指定行Python合并Excel 中的指定列P