Advertisement
Guest User

Untitled

a guest
May 7th, 2015
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 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 GenericArraySort_7
  8. {
  9.     class GenericArraySort_7
  10.     {      
  11.         static void SortArray<T>(List<T> list) where T : IComparable
  12.         {
  13.             for (int a = 0; a < list.Count - 1; a++)
  14.             {
  15.                 int minValue = a;
  16.                 for (int b = a + 1; b < list.Count; b++)
  17.                 {
  18.                     if (list[minValue].CompareTo(list[b])>0)
  19.                     {
  20.                         minValue = b;
  21.                     }
  22.                 }
  23.                 T temp = list[a];
  24.                 list[a] = list[minValue];
  25.                 list[minValue] = temp;
  26.             }
  27.             foreach (var l in list)
  28.             {
  29.                 Console.Write(l+" ");
  30.             }
  31.         }
  32.         static void Main(string[] args)
  33.         {
  34.             List<int> number = new List<int> { 3, 2, 16, 24, 5, 1, 27, 80, 9 };
  35.             List<string> words = new List<string> { "am", "em", "omo", "zaz", "cba", "baa" };
  36.             List<DateTime> dates = new List<DateTime> { new DateTime(2012, 02, 01),
  37.                             new DateTime(2015, 05, 06), new DateTime(1875, 03, 03) };
  38.  
  39.             SortArray(number);
  40.             Console.WriteLine();
  41.             SortArray(words);
  42.             Console.WriteLine();
  43.             SortArray(dates);
  44.             Console.WriteLine();
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement