Advertisement
xellscream

StringSorting

Jan 25th, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. using System;
  2.  
  3. class StringSorting
  4. {
  5.     static void Main()
  6.     {
  7.         int n, minKey;
  8.         string change;
  9.         string[] arr = { "cow", "elephant", "doggy", "tv", "bicycle", "I am insane" };
  10.         n = arr.Length;
  11.  
  12.         Console.WriteLine(string.Join(",", arr));
  13.         for (int a = 0; a < n -1; a++)
  14.         {
  15.             minKey = a;
  16.             for (int current = a + 1; current < n; current++)
  17.             {
  18.                 if (arr[current].Length < arr[minKey].Length)
  19.                 {
  20.                     minKey = current;
  21.                 }
  22.             }
  23.             change = arr[minKey];
  24.             arr[minKey] = arr[a];
  25.             arr[a] = change;
  26.         }
  27.  
  28.         Console.WriteLine(string.Join(",", arr));
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement