Si chiama bubble-sort
l'esempio che ti posto è scritto in VB6
ma si adatta facilmente a qualsiasi linguaggio
codice:Private Sub Form_Load() Dim vectINPUT(5), i, j, temp As Integer vectINPUT(0) = 10 vectINPUT(1) = 70 vectINPUT(2) = 1 vectINPUT(3) = 11 vectINPUT(4) = 69 'ordina i 5 numeri in modo crescente (bubble-sort) For i = 0 To 4 For j = 0 To 4 If vectINPUT(i) < vectINPUT(j) Then temp = vectINPUT(j) vectINPUT(j) = vectINPUT(i) vectINPUT(i) = temp End If Next j Next i 'stampa a video il valore più basso Text1.Text = vectINPUT(0) stampa a video il valore più alto Text2.Text = vectINPUT(4) End Sub

Rispondi quotando