Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp2
- {
- class Program
- {
- static Random random;
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- random = new Random();
- int[] array = new int[random.Next(5, 11)];
- for(int i = 0; i < array.Length; i++)
- {
- array[i] = random.Next(0, 11);
- }
- array = SortArray(array);
- }
- static void WriteNumbers(params int[] array)
- {
- foreach(int number in array)
- {
- Console.WriteLine(number);
- }
- }
- static int[] SortArray(int[] array)
- {
- for(int i = 0; i < array.Length; i++)
- {
- for(int j = 0; j < array.Length - i - 1; j++)
- {
- if (array[j] >= array[j + 1])
- {
- WriteWithSleep(array);
- int temp = array[j];
- array[j] = array[j + 1];
- array[j + 1] = temp;
- WriteWithSleep(array);
- }
- }
- }
- Console.WriteLine();
- return array;
- }
- static void WriteWithSleep(int[] array)
- {
- Console.Clear();
- Console.SetCursorPosition(0, 0);
- WriteNumbers(array);
- System.Threading.Thread.Sleep(500);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement