Ayuda ordenar un list de manera ascendente o descendente

Iniciado por themindmaster, 13 Octubre 2013, 17:02 PM

0 Miembros y 3 Visitantes están viendo este tema.

themindmaster

T_____T otro programa, en el cual tengo que pedir ayuda :( perdonen las molestias enserio :( T_T  el codigo no me funciona  me da error al principio :(
El sabio no se sienta para lamentarse, sino que se pone alegremente a su tarea de reparar el daño hecho.

Danyfirex

El insertionSort esta hecho en vb.net.

pero que has hecho que no te funciona?

themindmaster

El sabio no se sienta para lamentarse, sino que se pone alegremente a su tarea de reparar el daño hecho.

themindmaster

Solo quiero que me ordene los numeros añadidos al listbox si le doy al optionbotom ascendente me los ordenara de manera ascendente pero si le doy a descendente me los ordenara de manera descendente
El sabio no se sienta para lamentarse, sino que se pone alegremente a su tarea de reparar el daño hecho.

Danyfirex

A ver.

Te la pongo facil.

usa este algoritmo

Código (vb) [Seleccionar]
'true ascendente, false descendente
Public Sub BubbleSort(ByRef iaArray() As Long, Optional ByVal tipo As Boolean = True)

Dim n As Integer, i As Integer, j As Integer

    n = UBound(iaArray)

    For i = (n - 1) To 0 Step -1

        For j = 0 To i

If tipo = True Then
            If iaArray(j) > iaArray(j + 1) Then
            Swap iaArray(j), iaArray(j + 1)

            End If
Else
If iaArray(j) < iaArray(j + 1) Then
            Swap iaArray(j), iaArray(j + 1)

            End If
            End If
           

        Next j

    Next i

End Sub



que tienes que hacer. lo siguiente.



coger todos los elementos del listbox en un array.


luego

limpiar el listbox

luego llamar la rutina

Call BubbleSort(arreglo(), True)

luego llenar el listbox otra vez.


saludos




themindmaster

me da error :( dice que  se esperaba endsub T___T
saludos!
El sabio no se sienta para lamentarse, sino que se pone alegremente a su tarea de reparar el daño hecho.

Danyfirex


themindmaster

jajajaja perdona se me olvido recargar la pagina :)  mira el codigo
Código (vb) [Seleccionar]
Private Sub cmdañadir_Click()
lstnumero.AddItem (txtnumero)

End Sub

Private Sub cmdordenar_Click()
Public Sub BubbleSort(ByRef iaArray() As Long, Optional ByVal tipo As Boolean = True)

Dim n As Integer, i As Integer, j As Integer

    n = UBound(iaArray)

    For i = (n - 1) To 0 Step -1

        For j = 0 To i

If tipo = True Then
            If iaArray(j) > iaArray(j + 1) Then
            Swap iaArray(j), iaArray(j + 1)

            End If
Else
If iaArray(j) < iaArray(j + 1) Then
            Swap iaArray(j), iaArray(j + 1)

            End If
            End If


        Next j

    Next i

   
   


End Sub
El sabio no se sienta para lamentarse, sino que se pone alegremente a su tarea de reparar el daño hecho.

Danyfirex

Estas declarando un rutina dentro de otra :S

debería ser algo así.

Código (vb) [Seleccionar]




Private Sub Ordenar_Click()
Dim i As Long
Dim arreglo() As Long
ReDim arreglo(List1.ListCount - 1)
For i = 0 To List1.ListCount - 1
arreglo(i) = Int(List1.List(i))
Next
For i = 0 To UBound(arreglo)

Next
Call BubbleSort(arreglo(), True)
List1.Clear

For i = 0 To UBound(arreglo)
List1.AddItem arreglo(i)
Next



End Sub




'true ascendente, false descendente
Public Sub BubbleSort(ByRef iaArray() As Long, Optional ByVal tipo As Boolean = True)

Dim n As Integer, i As Integer, j As Integer

    n = UBound(iaArray)

    For i = (n - 1) To 0 Step -1

        For j = 0 To i

If tipo = True Then
            If iaArray(j) > iaArray(j + 1) Then
            Swap iaArray(j), iaArray(j + 1)

            End If
Else
If iaArray(j) < iaArray(j + 1) Then
            Swap iaArray(j), iaArray(j + 1)

            End If
            End If
           

        Next j

    Next i

End Sub





Private Sub Swap(ByRef xArg1, ByRef xArg2)

    Dim xTmp

    xTmp = xArg2

    xArg2 = xArg1

    xArg1 = xTmp

End Sub







PD: te recomiendo que leas mas sobre vb6( al menos lo básico ¬¬) lo estas haciendo al azar.

saludos

themindmaster

este es el codigo que puse y me da un errorsillo:
Código (vb) [Seleccionar]
Private Sub cmdañadir_Click()
lstnumero.AddItem (txtnumero)

End Sub

Private Sub cmdordenar_Click()
Dim i As Long
Dim arreglo() As Long
ReDim arreglo(List1.ListCount - 1)
For i = 0 To List1.ListCount - 1
arreglo(i) = Int(List1.List(i))
Next
For i = 0 To UBound(arreglo)

Next
Call BubbleSort(arreglo(), True)
List1.Clear

For i = 0 To UBound(arreglo)
List1.AddItem arreglo(i)
Next



End Sub




'true ascendente, false descendente
Public Sub BubbleSort(ByRef iaArray() As Long, Optional ByVal tipo As Boolean = True)

Dim n As Integer, i As Integer, j As Integer

    n = UBound(iaArray)

    For i = (n - 1) To 0 Step -1

        For j = 0 To i

If tipo = True Then
            If iaArray(j) > iaArray(j + 1) Then
            Swap iaArray(j), iaArray(j + 1)

            End If
Else
If iaArray(j) < iaArray(j + 1) Then
            Swap iaArray(j), iaArray(j + 1)

            End If
            End If


        Next j

    Next i

End Sub





Private Sub Swap(ByRef xArg1, ByRef xArg2)

    Dim xTmp

    xTmp = xArg2

    xArg2 = xArg1

    xArg1 = xTmp

End Sub

error 424 se requiere un objeto :(
El sabio no se sienta para lamentarse, sino que se pone alegremente a su tarea de reparar el daño hecho.