Advertisement
Nemo048

Untitled

Jul 15th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. namespace ConsoleApp2
  5. {
  6.     class Program
  7.     {
  8.         static Random random;
  9.  
  10.         static void Main(string[] args)
  11.         {
  12.             Console.CursorVisible = false;
  13.             random = new Random();
  14.             int[] array = new int[random.Next(5, 11)];
  15.  
  16.             for(int i = 0; i < array.Length; i++)
  17.             {
  18.                 array[i] = random.Next(0, 11);
  19.             }
  20.  
  21.  
  22.             array = SortArray(array);
  23.         }
  24.  
  25.         static void WriteNumbers(params int[] array)
  26.         {
  27.             foreach(int number in array)
  28.             {
  29.                 Console.WriteLine(number);
  30.             }
  31.         }
  32.  
  33.         static int[] SortArray(int[] array)
  34.         {
  35.             for(int i = 0; i < array.Length; i++)
  36.             {
  37.                 for(int j = 0; j < array.Length - i - 1; j++)
  38.                 {
  39.                     if (array[j] >= array[j + 1])
  40.                     {
  41.                         WriteWithSleep(array);
  42.  
  43.                         int temp = array[j];
  44.                         array[j] = array[j + 1];
  45.                         array[j + 1] = temp;
  46.  
  47.                         WriteWithSleep(array);
  48.                     }
  49.                    
  50.                 }
  51.             }
  52.             Console.WriteLine();
  53.             return array;
  54.         }
  55.  
  56.         static void WriteWithSleep(int[] array)
  57.         {
  58.             Console.Clear();
  59.             Console.SetCursorPosition(0, 0);
  60.             WriteNumbers(array);
  61.             System.Threading.Thread.Sleep(500);
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement