Advertisement
CuST0M1z3

SelectionSort

Jun 29th, 2013
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 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.  
  8. class SortingArray
  9. {
  10.     static void Main()
  11.     {
  12.         int n = int.Parse(Console.ReadLine());
  13.  
  14.         int[] arr = new int[n];
  15.  
  16.  
  17.         List<int> sortList = new List<int>();
  18.  
  19.         for (int i = 0; i < n; i++)
  20.         {
  21.             arr[i] = int.Parse(Console.ReadLine());
  22.         }
  23.  
  24.         List<int> arrList = arr.ToList();
  25.  
  26.         while (arrList.Count > 0)
  27.         {
  28.             int min = arrList[0];
  29.             for (int j = 0; j < arrList.Count; j++)
  30.             {
  31.                 if (arrList[j] <= min)
  32.                 {
  33.                     min = arrList[j];
  34.                 }
  35.             }
  36.             sortList.Add(min);
  37.             arrList.Remove(min);          
  38.         }
  39.              
  40.         Console.WriteLine();
  41.         foreach (var num in sortList)
  42.         {
  43.             Console.Write(num + " ");
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement