SHARE
TWEET

Untitled

a guest Sep 20th, 2015 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 SortArrayOfNumbersUsingSelectionSort
  9. {
  10.     static void Main()
  11.     {
  12.         int[] numArr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  13.        
  14.  
  15.         for (int i = 0; i < numArr.Length - 1; i++)
  16.         {
  17.             int min = i;
  18.  
  19.             for (int j = i + 1; j < numArr.Length; j++)
  20.             {
  21.                 if (numArr[j] < numArr[min])
  22.                 {
  23.                     min = j;
  24.                 }
  25.             }
  26.             if (min != i)
  27.             {
  28.                 int currNum = numArr[i];
  29.                 int currNum2 = numArr[min];
  30.                 Swap(ref currNum, ref currNum2);
  31.             }
  32.         }
  33.         Console.WriteLine(string.Join(" ", numArr));
  34.  
  35.     }
  36.  
  37.     static void Swap(ref int currNum, ref int currNum2)
  38.     {
  39.         int temp = currNum;
  40.         currNum = currNum2;
  41.         currNum2 = temp;
  42.     }
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top