Visual Basic - metodo burbuja

Life is soft - evento anual de software empresarial
 
Vista:

metodo burbuja

Publicado por smile (10 intervenciones) el 08/12/2005 02:24:54
Tengo que hacer un programa con arreglos dinamicos, en donde el usuario introduce un numero de temperaturas, tengo que ordenarlas por el metodo burbuja y sacar la media, no se que este haciendo mal que el programa me lo corre todo feo, alguien puede ayudarme y decirme mis errores porfas gacias.
este es el codigo:
Dim sum As Integer, aux As Integer


Private Sub Command1_Click()
Dim arrtemp()
total = Val(Text1.Text)
ReDim arrtemp(total)


For i = 0 To total
arrtemp(i) = InputBox("introduce las temperaturas")
Print arrtemp(i)
Next i

aux = 0
For i = 0 To (total - 1)
For j = 0 To (total - 1)
If arrtemp(j) > arrtemp(j + 1) Then
aux = arrtemp(j)
arrtemp(j) = arrtemp(j + 1)
arrtemp(j + 1) = aux
End If
List1.AddItem arrtemp(j)
Next j
sum = 0

sum = sum + arrtemp(i)
MEDIA = sum / total

Label2.Caption = MEDIA
Next i

End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:metodo burbuja

Publicado por jose carlos (340 intervenciones) el 08/12/2005 14:40:38
prueba asi

Dim arrtemp()
total = Val(Text1.Text)
ReDim arrtemp(total)

sum = 0

For i = 0 To total
arrtemp(i) = InputBox("introduce las temperaturas")
Print arrtemp(i)
Print "---"
Next i

aux = 0
For i = 0 To (total)
For j = i To (total - 1)
If arrtemp(i) > arrtemp(j) Then
aux = arrtemp(i)
arrtemp(i) = arrtemp(j)
arrtemp(j) = aux
End If
List1.AddItem arrtemp(j)
Next j

sum = sum + arrtemp(i)

MEDIA = sum / total

Label2.Caption = MEDIA
Next i
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar