ORDENACION POR BURBUJA

jueves, 13 de noviembre de 2008

Elabore una aplicación que permita leer N números de tipo entero, y a continuación los visualice ordenados en forma ascendente o descendente.


Para el desarrollo de esta aplicación, proceda a ubicar los siguientes controles en el formulario:

3 marcos
1 caja de texto
1 control lista
2 botones de opción
3 botones de comando

En seguida proceda a establecer las propiedades según se indica:

Form1

Nombre
FrmBurbuja

BorderStyle
3-Fixed Dialog

Caption
Ordenación por burbuja

Moveable
False

Frame1

Nombre
FraNumero

Caption
Ingrese un nuevo número:

Frame2

Nombre
FraLista

Caption
Lista de números:

Frame3

Nombre
FraOrden

Caption
Orden:

Text1

Nombre
TxtNumero

Text


List1

Nombre
LstNumero

List


Option1

Nombre
OptAscendente

Caption
Ascendente

Value
True

Option2

Nombre
OptDescendente

Caption
Descendente

Value
False

Command1

Nombre
CmdAnnadir

Caption
&Añadir

Default
True

Command2

Nombre
CmdOrdenar

Caption
&Ordenar

Command3

Nombre
CmdSalir

Caption
&Salir

Picture
C:\Archivos de programa\Microsoft Visual
Studio\Common\Graphics\Icons\Arrows\
Point04.ico

Style
1-Graphical

Una vez establecidas las propiedades proceda a ingresar el código que se indica a continuación:
Private Sub CmdAceptar_Click()
If IsNumeric(TxtNumero.Text) Then
LstNumero.AddItem TxtNumero.Text
TxtNumero.Text = “”
TxtNumero.SetFocus
Else
MsgBox “Ingrese un número”, vbCritical, “Mensaje”
TxtNumero.SelStart = 0
TxtNumero.SelLength = Len(TxtNumero.Text)
TxtNumero.SetFocus
End If
End Sub

Private Sub CmdOrdenar_Click()
Dim I As Integer, J As Integer, T As Integer, N As Integer
Dim A() As Integer
N = LstNumero.ListCount
ReDim A(N)
For I = 0 To N - 1
A(I) = LstNumero.List(I)
Next I
If OptAscendente.Value Then
For I = 0 To N - 2
For J = I + 1 To N - 1
If A(I) > A(J) Then
T = A(I)
A(I) = A(J)
A(J) = T
End If
Next J
Next I
End If

If OptDescendente.Value Then
For I = 0 To N - 2
For J = I + 1 To N - 1
If A(I) < t =" A(I)" i =" 0" cancel =" True">

0 comentarios: