Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- public class Program
- {
- public static void Main()
- {
- int[] nums = {1, 2, 3, 4, 5, 1, 0 , 5};
- string[] words = {"zaz", "cba", "baa", "azis"};
- DateTime[] dates =
- {
- new DateTime(2002,3,1), new DateTime(2015,5,6), new DateTime(2014,1,1)
- };
- List<int> numList = new List<int>(new int[] { 1, 2, 3, 4 ,5, 1, 0, 5} );
- List<string> stringList = new List<string>(new string[] { "zaz", "cba", "baa", "azis"} );
- List<DateTime> dateList = new List<DateTime>(new DateTime[] {
- new DateTime(2002,3,1), new DateTime(2015,5,6), new DateTime(2014,1,1)
- } );
- SortArray<int>(numList);
- SortArray<string>(stringList);
- SortArray<DateTime>(dateList);
- }
- static void SortArray<T>(IList<T> coll) where T : IComparable
- {
- bool areSorted = false;
- do
- {
- areSorted = true;
- for (int i = 0; i < coll.Count - 1; i++)
- {
- if (coll[i].CompareTo(coll[i+1]) > 0)
- {
- var exchangeValue = coll[i];
- coll[i] = coll[i + 1];
- coll[i + 1] = exchangeValue;
- areSorted = false;
- }
- }
- } while (areSorted == false);
- Console.WriteLine(string.Join(",",coll));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement