Skip to content

Instantly share code, notes, and snippets.

@aristeoibarra
Last active February 26, 2021 07:11
Show Gist options
  • Save aristeoibarra/ac8e27e32bd2ada79ebd3c334c2c6c65 to your computer and use it in GitHub Desktop.
Save aristeoibarra/ac8e27e32bd2ada79ebd3c334c2c6c65 to your computer and use it in GitHub Desktop.
Bubble Sort
using System;
namespace BubbleSort
{
class Program
{
static void Main(string[] args)
{
int[] numbers = new int[10];
for (int i = 0; i < numbers.Length; i++)
{
numbers[i] = new Random().Next(1,20);
}
for (int i = 0; i < numbers.Length; i++)
{
for (int j = 0; j < numbers.Length - 1; j++)
{
if (numbers[j] > numbers[j + 1])
{
int aux = numbers[j];
numbers[j] = numbers[j + 1];
numbers[j + 1] = aux;
}
}
}
foreach (int i in numbers)
{
Console.Write(i + " ");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment