Advertisement
shady_obeyd

03.Sort Array of Strings

Jul 18th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 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 _03.SortArrayOfStrings
  8. {
  9.     class SortArrayOfStrings
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] input = Console.ReadLine().Split(' ');
  14.  
  15.             List<string> list = new List<string>();
  16.  
  17.             for (int firstIndex = 0; firstIndex < input.Length; firstIndex++)
  18.             {
  19.                 string elementToInsert = input[firstIndex];
  20.                 bool isInserted = false;
  21.  
  22.                 for (int secondIndex = 0; secondIndex < list.Count; secondIndex++)
  23.                 {
  24.                     if (elementToInsert.CompareTo(list[secondIndex]) < 0)
  25.                     {
  26.                         list.Insert(secondIndex, elementToInsert);
  27.                         isInserted = true;
  28.                         break;
  29.                     }
  30.                 }
  31.                 if (!isInserted)
  32.                 {
  33.                     list.Add(elementToInsert);
  34.                 }
  35.             }
  36.             Console.WriteLine(string.Join(" ", list));
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement