Advertisement
optybg

Untitled

Mar 1st, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. {
  6.     public class _03SortArrayofStrings
  7.     {
  8.         public static void Main()
  9.         {
  10.             var inputStrings = Console.ReadLine();
  11.  
  12.             var inputList = new List<string>(inputStrings.Split().ToList());
  13.  
  14.             bool swapped = true;
  15.             while (swapped)
  16.             {
  17.                 swapped = false;
  18.                 for (int i = 1; i < inputList.Count; i++)
  19.                 {
  20.                     int compare = 0;
  21.                     compare = inputList[i - 1].CompareTo(inputList[i]);
  22.                     if (compare == 1)
  23.                     {
  24.                         var temp = inputList[i - 1];
  25.                         inputList[i - 1] = inputList[i];
  26.                         inputList[i] = temp;
  27.                         swapped = true;
  28.                     }
  29.                 }
  30.             }
  31.  
  32.             Console.WriteLine(string.Join(" ", inputList));
  33.  
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement