Advertisement
son4etyyy

MethodForSortingStrings

Jan 19th, 2013
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2. class MethodForSortingStrings
  3. {
  4.     /*You are given an array of strings.
  5.      * Write a method that sorts the array by the length of its elements
  6.      * (the number of characters composing them).*/
  7.     static void Main()
  8.     {
  9.         string temp;
  10.         string[] a = { "aaaaaaa", "nnnn", "ss", "iiiii", "ooo" };
  11.         for (int i = 0; i < a.Length; i++)
  12.         {
  13.             for (int j = i; j < a.Length; j++)
  14.             if (a[i].Length > a[j].Length)
  15.             {
  16.                 temp = a[i];
  17.                 a[i] = a[j];
  18.                 a[j] = temp;
  19.             }
  20.         }
  21.         for (int i = 0; i < a.Length; i++)
  22.         {
  23.             Console.WriteLine(a[i]);
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement