bgmc Posted December 21, 2009 at 10:57 PM Report Share #301757 Posted December 21, 2009 at 10:57 PM Boas a todos. Ainda ando nos primeiros passos de programação em visual basic. O problema é o seguinte: Digitar seis numeros, e ordená-los. Gostaria de saber se existe algum metodo facil para ordenar. obrigado a todos Link to comment Share on other sites More sharing options...
jpaulino Posted December 21, 2009 at 11:06 PM Report Share #301760 Posted December 21, 2009 at 11:06 PM Por exemplo (usando colecções) Dim numList As New List(Of Integer) numList.Add(1) numList.Add(24) numList.Add(12) numList.Add(33) numList.Add(8) numList.Sort() For Each num As Integer In numList Debug.WriteLine(num) Next Link to comment Share on other sites More sharing options...
jpaulino Posted December 21, 2009 at 11:09 PM Report Share #301761 Posted December 21, 2009 at 11:09 PM Ou se preferires um array: Dim numList(5) As Integer numList(0) = 12 numList(1) = 1 numList(2) = 24 numList(3) = 3 numList(4) = 8 numList(5) = 2 Array.Sort(numList) For Each num As Integer In numList Debug.WriteLine(num) Next Link to comment Share on other sites More sharing options...
ribeiro55 Posted December 22, 2009 at 02:50 AM Report Share #301779 Posted December 22, 2009 at 02:50 AM Ou talvez até algo mais "manual", como costumam pedir nos exercicíos: Dim Numeros() = {6, 3, 1, 26, 13, 24, 8, 54, 12, 32, 65, 22, 7} Dim TempNum As Integer For i As Integer = Numeros.Length - 1 To 0 Step -1 If i >= 1 Then If Numeros(i) < Numeros(i - 1) Then TempNum = Numeros(i) Numeros(i) = Numeros(i - 1) Numeros(i - 1) = TempNum i = Numeros.Length End If End If Next Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips" Link to comment Share on other sites More sharing options...
jpaulino Posted December 22, 2009 at 09:47 PM Report Share #301919 Posted December 22, 2009 at 09:47 PM Ou talvez até algo mais "manual", como costumam pedir nos exercicíos: Um bubble sort 😉 Link to comment Share on other sites More sharing options...
ribeiro55 Posted December 23, 2009 at 03:15 AM Report Share #301968 Posted December 23, 2009 at 03:15 AM OFFTOPIC Mas isto até tem nome? 😉🙂😉 eu fui Googlar "bubble sort" Nunca tinha ouvido falar ? @bgmc Diz qualquer coisa! Já tens para aqui material 🙂 Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips" Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now