Ver Mensaje Individual
  #2 (permalink)  
Antiguo 06/01/2003, 14:13
Avatar de AlZuwaga
AlZuwaga
Colaborador
 
Fecha de Ingreso: febrero-2001
Ubicación: 34.517 S, 58.500 O
Mensajes: 14.550
Antigüedad: 24 años, 2 meses
Puntos: 535
Por el método de la burbuja:

Two-Dimensional Array Sort Using Bubble Sort


Acá lo intenté recrear utilizando FileSystemObject, pero tuve un par de problemas:

1- no pude crear el array dinámicamente. En realidad, no se como establecer dinámicamente la primer dimensión del array (vamos, la cantidad de archivos):

Dim arrDualArray(18,1)

18 es la cantidad de archivos que YO tengo en el root del servidor y no se por qué no me permite hacer esto...

Dim arrDualArray(Carpeta.Files.Count-1,1)

... siendo que Carpeta.Files.Count-1 es igual, en este caso, a 18



2- Al ser las fechas en formato DD/MM/AAAA HH:MM:SS, no ordenaba correctamente. Así que decidí pasarlas al formato AAAAMMDD para que veas cómo ordena al menos de manera numérica

Ahora si, el código:



<%
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set Carpeta = FSO.GetFolder(Server.MapPath("/"))
Set ArchivosDelDir = Carpeta.Files

Cantidad = Carpeta.Files.Count-1
Response.Write "Cantidad de archivos: " & Cantidad & "<br><br>"

Dim arrDualArray(18,1)

j = 0
k = 0

For Each Archivo in ArchivosDelDir

arrDualArray(j,k) = Archivo.name
k = 1
arrDualArray(j,k) = Right(Left(Archivo.DateLastModified, 10), 4) & Mid(Left(Archivo.DateLastModified, 10), 4, 2) &

Left(Left(Archivo.DateLastModified, 10), 2)

k = 0
j = j + 1

Next


Response.Write "<b><u>Unsorted List of 2d Array:</u></b><br>"
For i = LBound(arrDualArray) to UBound(arrDualArray)
Response.Write arrDualArray(i, 0) & " - "
Response.Write arrDualArray(i, 1) & "<BR>"
Next

Sub DualSorter( byRef arrArray, DimensionToSort )
Dim row, j, StartingKeyValue, StartingOtherValue, _
NewStartingKey, NewStartingOther, _
swap_pos, OtherDimension
Const column = 1

' Ensure that the user has picked a valid DimensionToSort
If DimensionToSort = 1 then
OtherDimension = 0
ElseIf DimensionToSort = 0 then
OtherDimension = 1
Else
'Shoot, invalid value of DimensionToSort
Response.Write "Invalid dimension for DimensionToSort: " & _
"must be value of 1 or 0."
Response.End
End If

For row = 0 To UBound( arrArray, column ) - 1
'Start outer loop.

'Take a snapshot of the first element
'in the array because if there is a
'smaller value elsewhere in the array
'we'll need to do a swap.
StartingKeyValue = arrArray ( row, DimensionToSort )
StartingOtherValue = arrArray ( row, OtherDimension )

' Default the Starting values to the First Record
NewStartingKey = arrArray ( row, DimensionToSort )
NewStartingOther = arrArray ( row, OtherDimension )

swap_pos = row

For j = row + 1 to UBound( arrArray, column )
'Start inner loop.
If arrArray ( j, DimensionToSort ) < NewStartingKey Then
'This is now the lowest number -
'remember it's position.
swap_pos = j
NewStartingKey = arrArray ( j, DimensionToSort )
NewStartingOther = arrArray ( j, OtherDimension )
End If
Next

If swap_pos <> row Then
'If we get here then we are about to do a swap
'within the array.
arrArray ( swap_pos, DimensionToSort ) = StartingKeyValue
arrArray ( swap_pos, OtherDimension ) = StartingOtherValue

arrArray ( row, DimensionToSort ) = NewStartingKey
arrArray ( row, OtherDimension ) = NewStartingOther

End If
Next
End Sub

call DualSorter(arrDualArray, 1)

Response.Write "<p><b><u>Sorted List of 2d Array by Number:</u></b><br>"
For i = LBound(arrDualArray) to UBound(arrDualArray)
Response.Write arrDualArray(i, 0) & " - "
Response.Write arrDualArray(i, 1) & "<BR>"
Next

call DualSorter(arrDualArray, 0)

Response.Write "<p><b><u>Sorted List of 2d Array by Name:</u></b><br>"
For i = LBound(arrDualArray) to UBound(arrDualArray)
Response.Write arrDualArray(i, 0) & " - "
Response.Write arrDualArray(i, 1) & "<BR>"
Next
%>