Ordenamiento por selección en Visual Basic.NET [50]
En este tutorial vamos a hacer un Ordenamiento por selección en Visual Basic.NET. Su funcionamiento es el siguiente:
- Buscar el mínimo elemento de la lista.
- Intercambiarlo con el primero.
- Buscar el siguiente mínimo en el resto de la lista.
- Intercambiarlo con el segundo.
- Así hasta terminar con la lista.
Codigo: https://github.com/programadornovato/VisualBasic/commit/ec48791e7a6f911be4bc9c1fe48e42d384aebc0f
Imports System
'Autor: Programador Novato
'Fecha: 01/01/2021
'Este modulo sirve para ense�ar como funciona Visual Basic.NET
Module Program
'Este codigo escribe un texto en amarillo con fondo azul
Public Sub Main(args As String())
Dim listaNumeros = New Integer(4) {}
For i = 0 To listaNumeros.Length - 1
Console.WriteLine("Humano, ingresa el elemento " & (i + 1))
listaNumeros(i) = Integer.Parse(Console.ReadLine())
Next
Dim menor = 0
Dim pos = 0
Dim tem = 0
For i = 0 To listaNumeros.Length - 2
menor = listaNumeros(i)
pos = i
For j = i + 1 To listaNumeros.Length - 1
If listaNumeros(j) < menor Then
menor = listaNumeros(j)
pos = j
End If
Next
If pos <> i Then
tem = listaNumeros(i)
listaNumeros(i) = listaNumeros(pos)
listaNumeros(pos) = tem
End If
Next
Console.WriteLine("Humano aqui esta tu pinche lista de numeros ordenado de forma acendente")
For i = 0 To listaNumeros.Length - 1
Console.WriteLine(listaNumeros(i))
Next
Console.WriteLine("Humano aqui esta tu pinche lista de numeros ordenado de forma decndente")
For i = listaNumeros.Length - 1 To 0 Step -1
Console.WriteLine(listaNumeros(i))
Next
Console.Read()
End Sub
End Module
Curso de VB.NET⛓️: https://www.youtube.com/watch?v=aiquJHzxNWw&list=PLCTD_CpMeEKSFwAFjvrfpvSwxmbs2maMo&ab_channel=programadornovato
[CURSO] C##️⃣: https://www.youtube.com/watch?v=NKPMGY6NCko&list=PLCTD_CpMeEKQSOU8Vf9VHXrZa2rc8X0X5&index=1&t=3s&ab_channel=programadornovatoprogramadornovato
[CURSO] C# CON FORMULARIOS#️⃣: https://www.youtube.com/watch?v=l0_U4oyOuns&list=PLCTD_CpMeEKTBih1VgeunCjc83ZQ6UBMI&index=1&ab_channel=programadornovatoprogramadornovato
[Curso] C# MYSQL#️⃣: https://www.youtube.com/watch?v=-5CXNXHIzWk&list=PLCTD_CpMeEKR_4q0-7BxGHXqH0bgpqw5q&ab_channel=programadornovato
[CURSO] C++ DE 0 A HEROE 🦸: https://www.youtube.com/watch?v=APN8aCyPvww&list=PLCTD_CpMeEKTofxs7iottRxJ5YPM7BOcc&ab_channel=programadornovato
[Curso] Java Netbeans GUI Completo☕: https://www.youtube.com/watch?v=18UA7X2ss8g&list=PLCTD_CpMeEKThfXo8D-RXOGu5FarO7_qv&ab_channel=programadornovato
Anterior tutorial Siguiente tutorial