Advertisement
YavorGrancharov

Sort_Array_of_Strings_(insertSort)

Jul 1st, 2017
98
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.  
  5. namespace Sort_Array_of_Strings
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string[] array = Console.ReadLine().Split(' ').ToArray();
  12.             InsertSort(array);
  13.             Console.WriteLine(string.Join(" ", array));
  14.         }
  15.        
  16.         static void InsertSort(IComparable[] newArray)
  17.         {
  18.             int i, j;
  19.             for (i = 1; i < newArray.Length; i++)
  20.             {
  21.                 IComparable value = newArray[i];
  22.                 j = i - 1;
  23.                 while ((j >= 0) && (newArray[j].CompareTo(value) > 0))
  24.                 {
  25.                     newArray[j + 1] = newArray[j];
  26.                     j--;
  27.                 }
  28.                 newArray[j + 1] = value;
  29.             }
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement