Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- class GenericArraySort
- {
- static void Main()
- {
- object[] input = Console.ReadLine().Split().ToArray();
- SortArray(input);
- }
- static void SortArray(object[] twinInput)
- {
- bool intType = false;
- bool strType = false;
- bool dtType = false;
- for (int g = 0; g < twinInput.Length - 1; g++)
- {
- if (twinInput[g].GetType() == typeof(int))
- {
- intType = true;
- }
- if (twinInput[g].GetType() == typeof(string))
- {
- strType = true;
- }
- if (twinInput[g].GetType() == typeof(DateTime))
- {
- dtType = true;
- }
- }
- if (intType)
- {
- int[] intSeq = twinInput.Select(p => (int)p).ToArray();
- int temp;
- for (int i = 0; i < twinInput.Length - 1; i++)
- {
- int min = i;
- for (int j = i + 1; j < twinInput.Length; j++)
- {
- if (intSeq[min] > intSeq[j])
- {
- min = j;
- }
- }
- if (min != i)
- {
- temp = intSeq[i];
- intSeq[i] = intSeq[min];
- intSeq[min] = temp;
- }
- }
- Console.WriteLine(string.Join(" ", intSeq));
- }
- if (strType)
- {
- string[] strSeq = twinInput.Select(p => p.ToString()).ToArray();
- Array.Sort(strSeq);
- Console.WriteLine(string.Join(" ", strSeq));
- }
- if (dtType)
- {
- DateTime[] dTSeq = Array.ConvertAll(twinInput, d => (DateTime)d).ToArray();
- Array.Sort(dTSeq);
- Console.WriteLine(string.Join(" ", dtType));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement