labs.insert-title.com

Bubble Sort Multi-dimensional Array

Not that this is any news to anyone - but I found myself onsite at a clients server and simply could not pull this off without the assitance of my good friend Dan Kirkwood at Eagle Innovations and just so I dont forget again here is a quick and easy bubble sort function. This one is really meant for use with a two dimensional array, the first element being numeric, which is what it will sort by.

Use:

sortthis arr

All done!


sub sortthis (byref arr)

dim y, y2, fld1, fld2

fld1 = ""
fld2 = ""

for y = 0 to ubound(arr, 2)
	for y2 = y + 1 to ubound(arr, 2)

		if arr(0, y2) > arr(0, y) then
			fld1 = arr(0, y)
			fld2 = arr(1, y)

			arr(0, y) = arr(0, y2)
			arr(1, y) = arr(1, y2)

			arr(0, y2) = fld1
			arr(1, y2) = fld2
		end if
	next
next

end sub





Discussion

Ex ASP

Ughhh, ASP code, yuck!

New comments are currently disabled, you can find me @joemaddalone Comments temporarily disabled for now, you can find me @joemaddalone