Skip to content

Instantly share code, notes, and snippets.

@Strelok78
Created May 5, 2025 15:37
Show Gist options
  • Save Strelok78/3e8d584e61f5d5b1bd1d49a83e268ae3 to your computer and use it in GitHub Desktop.
Save Strelok78/3e8d584e61f5d5b1bd1d49a83e268ae3 to your computer and use it in GitHub Desktop.
sort array (bubble sort)
using System;
namespace iJuniorPractice
{
class Program
{
static void Main(string[] args)
{
int[] numbers = {1, 7, 3, 42, 52, 9, 19, 17, 21, 0, 1, 200};
int temp;
for (int j = 1; j < numbers.Length - 1; j++)
{
for (int i = 0; i < numbers.Length - j; i++)
{
if (numbers[i] > numbers[i + 1])
{
temp = numbers[i];
numbers[i] = numbers[i + 1];
numbers[i + 1] = temp;
}
}
}
foreach (var number in numbers)
{
Console.WriteLine(number);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment