Advertisement
Lamms

InsertSort

Sep 23rd, 2015
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 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 _03InsertSort
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.            int[] arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
  14.            
  15.            for (int i = 1; i < arr.Length; i++)
  16.            {
  17.                    for (int j = i; j > 0; j--)
  18.                    {
  19.                        if (arr[j - 1] > arr[j])
  20.                        {
  21.                            int temp = arr[j - 1];
  22.                            arr[j - 1] = arr[j];
  23.                            arr[j] = temp;
  24.                        }
  25.                    }
  26.            }
  27.  
  28.            for (int i = 0; i < arr.Length; i++)
  29.            {
  30.                Console.Write(arr[i]+ " ");
  31.            }
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement