Created
May 5, 2025 15:37
-
-
Save Strelok78/3e8d584e61f5d5b1bd1d49a83e268ae3 to your computer and use it in GitHub Desktop.
sort array (bubble sort)
This file contains hidden or 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 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