Advertisement
gabrielesilinic

Selection Sort

Mar 11th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Sort
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Random rnd = new Random();
  14.             int[] arr = new int [80];
  15.             for (int i = 0; i < arr.Length; i++)
  16.             {
  17.                 arr[i] = rnd.Next(700);
  18.             }
  19.             SelectionSort(arr);
  20.             foreach (var item in arr)
  21.             {
  22.                 Console.WriteLine(item);
  23.             }
  24.             Console.WriteLine();
  25.         }
  26.         static void SelectionSort(int[] arr)
  27.         {
  28.             for (int i = 0; i < arr.Length; i++)
  29.             {
  30.                 for (int j = 0; j < arr.Length; j++)
  31.                 {
  32.                     if (arr[i] < arr[j])
  33.                     {
  34.                         var tmp = arr[i];
  35.                         arr[i] = arr[j];
  36.                         arr[j] = tmp;
  37.                     }
  38.                 }
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement