Last active
February 26, 2021 07:11
-
-
Save aristeoibarra/ac8e27e32bd2ada79ebd3c334c2c6c65 to your computer and use it in GitHub Desktop.
Bubble Sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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