# A 2-D Bubble Sort Subroutine

## Domino Resources - Part 2

### Looking for something else?

Sort routines for a single list of values have been around for awhile, but
recently I needed to sort a list of form names and keep the corresponding list
of form aliases correctly associated.

I modified a Bubble Sort routine I've used in the past to input two variant
arrays, sort the first in ascending order, and reorder the second array to
correspond with each item's original first-array partner.
' Paste the Sub into the Declarations section of a form, button, etc.

Sub Bubble_Sort2 (ary1 As Variant, ary2 As Variant)

' Returns sorted array for ary1 and corresponding values for ary2
' based on a complexity of O(n^2) using a bubble sort
Dim top1, top2, bot1, bot2, cur, cur2 As Integer
Dim tmp1, tmp2 As Variant
If Not Isarray(ary1) Then Print "SORT: First variant not an array" :Exit Sub
If Not Isarray(ary2) Then Print "SORT: Second variant not an array" :Exit Sub
top1=Ubound (ary1)
top2=Ubound (ary2)
bot1=Lbound (ary1)
bot2=Lbound (ary2)
If top1=bot1 Then Print "SORT: Single-value array" : Exit Sub
If (top1-bot1)<>(top2-bot2) Then Print "SORT: Arrays not same size" : Exit Sub
For cur=bot1 To top1
cur2=cur
Do While cur2 > bot1 'bubble up
If (ary1(cur2) > ary1(cur2-1)) Then
Exit Do
Else
'swap
tmp1=ary1(cur2)
tmp2=ary2(cur2)
ary1(cur2)=ary1(cur2-1)
ary2(cur2)=ary2(cur2-1)
ary1(cur2-1)=tmp1
ary2(cur2-1)=tmp2
End If
cur2=cur2-1
Loop
Next
End Sub

' A button action on a form with four multi-value text fields; Input_1,
Input_2, Output_1 and Output_2
' Enter several unsorted values in Input_1 and an identical number of values
in Input_2, and click the button.
' The 1st set of values will be sorted and placed into Output_1 and the 2nd
set will be placed into Output_2
' in the order they now correspond with their original counterparts from the
1st set.

Sub Click(Source As Button)
Dim ws As New NotesUIWorkspace
Dim ui As NotesUIDocument
Dim doc As NotesDocument
Dim itm1, itm2 As NotesItem
Dim v1, v2 As Variant
Dim ary() As Variant
Set ui = ws.CurrentDocument
Set doc = ui.Document
Set itm1 = doc.GetFirstItem("Input_1")
Set itm2 = doc.GetFirstItem("Input_2")
ct%=0
v1 = itm1.Values
v2 = itm2.Values
Call Bubble_Sort2 (v1, v2)
doc.Output_1 = v1
doc.Output_2 = v2
End Sub

This was last published in November 2000

#### Start the conversation

Send me notifications when other members comment.

## SearchWindowsServer

• ### Windows Management Framework 5 update gives PowerShell users a fix

Microsoft answered admin requests for new features and fixed several bugs with its WMF 5.1 release, giving users a slew of ...

• ### Pester PowerShell unit testing ensures quality code

PowerShell jockeys can turn to the Pester unit testing framework to ensure the code they write is up to snuff.

• ### Microsoft software-defined networking gets baked into Windows Server

The Microsoft SDN technology that comes in the Windows Server 2016's Datacenter edition features a range of basic to nuanced ...

## Search400

• ### iSeries tutorials

Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

• ### V6R1 upgrade planning checklist

When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

• ### Connecting multiple iSeries systems through DDM

Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

## SearchEnterpriseLinux

• ### SUSE Linux jumps on the open private cloud deployment train

SUSE Linux Enterprise planning private cloud deployment with OpenStack weight behind it. NVIDIA works on Linux drivers for ...

• ### Want one of the many Linux jobs out there? Time to go back to class

Does extended education from the Linux Foundation and others help graduates meet the demands of today’s Linux jobs? Some say yes.

• ### Ubuntu ARM server AMI for Amazon EC2 offers fast access in the cloud

Canonical’s Ubuntu ARM server AMI for Amazon EC2 provide open source shops with a fast ARM server for the cloud.

## SearchDataCenter

• ### HPE-SimpliVity deal raises support, price and development questions

With HPE's buy of No. 2 SimpliVity -- the first big deal in the HCI space -- IT pros see a more robust offering, but also higher ...

• ### Converged infrastructure drop-off doesn't mean data center death

Traditional converged infrastructure has been supplanted by hyper-converged infrastructure and cloud computing, but it remains a ...

• ### New options to evolve your data backup and recovery plan

The server backup market first evolved to protect VMs, but now it's undergoing another transformation. Find out how it's evolved ...

## SearchExchange

• ### Beware of these six Office 365 cons for IT shops accustomed to on premises

Office 365 offers many benefits, but there are plenty of cons to consider before leaping to this cloud-based productivity suite ...

• ### Five reasons for an Office 365 hybrid deployment

Not all organizations can go all-in on cloud. There are five reasons why a hybrid Office 365 arrangement makes sense for those ...

Admins must keep a close eye on Exchange Server to ensure it runs at peak performance. If cost is an issue, there are a number of...

## SearchContentManagement

• ### Why SharePoint Framework could benefit business, not just developers

SharePoint Framework heralds a new, mobile-friendly, low-code era for Microsoft, which may give some organizations without .NET ...

• ### Using Microsoft MyAnalytics to improve workers' time management

Microsoft MyAnalytics has been hailed as the next great thing for analyzing worker productivity. But how can employees be assured...

• ### Is the Drupal content management system right for your business?

The open source Drupal content management system offers users responsive design and WYSIWYG content and web development tools, as...

Close