1
The numbers are generated randomly in the vector, but when I call the function Bublle to sort the result returns 0. Someone can help me????
using System;
namespace BubbleSort_CSharp
{
class Program
{
static void Main(string[] args)
{
int[] vetor = new int[10];
Random rnd = new Random();
Console.WriteLine("Vetor Desordenado\n");
for (int i = 0; i <= vetor.Length; i++)
{
Console.WriteLine("Elemento: {0}", rnd.Next(1, 100));
}
bubbleSort(vetor, vetor.Length);
Console.WriteLine("\nVetor Ordenado\n");
for (int i = 0; i <= vetor.Length; i++)
{
Console.WriteLine("Elemento: {0} ", vetor[i]);
}
Console.ReadLine();
}
static void bubbleSort(int[] vetor, int length)
{
int trocas = 0;
for (int i = 0; i < length - 1; i++)
{
for (int j = 0; j < length - (i + 1); j++)
{
if (vetor[j] > vetor[j + 1])
{
trocas = vetor[j];
vetor[j] = vetor[j + 1];
vetor[j + 1] = trocas;
}
}
}
}
}
}