Advertisement
CuST0M1z3

7.SortingArray

Jun 29th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 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.         for (int i = 0; i < n; i++)
  17.         {
  18.             arr[i] = int.Parse(Console.ReadLine());
  19.         }
  20.                
  21.         int minValue = 0;
  22.         int index = 0;
  23.  
  24.         for (int i = 0; i < (n - 1); i++)
  25.         {
  26.             int currentValue = arr[i];
  27.             index = i;
  28.             for (int j = (i + 1); j < n; j++)
  29.             {
  30.                 if (arr[j] < currentValue)
  31.                 {
  32.                     minValue = arr[j];
  33.                     index = j;
  34.                 }          
  35.             }
  36.             if (index != i)
  37.             {
  38.                 arr[index] = currentValue;
  39.                 arr[i] = minValue;
  40.             }
  41.         }
  42.  
  43.         foreach (var num in arr)
  44.         {
  45.             Console.Write(num + " ");
  46.         }
  47.  
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement