Advertisement
Guest User

Untitled

a guest
Sep 25th, 2015
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 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.  
  8. class GenericArraySort
  9. {
  10. static void Main()
  11. {
  12. object[] input = Console.ReadLine().Split().ToArray();
  13.  
  14. SortArray(input);
  15.  
  16. }
  17. static void SortArray(object[] twinInput)
  18. {
  19. bool intType = false;
  20. bool strType = false;
  21. bool dtType = false;
  22.  
  23. for (int g = 0; g < twinInput.Length - 1; g++)
  24. {
  25. if (twinInput[g].GetType() == typeof(int))
  26. {
  27. intType = true;
  28. }
  29.  
  30. if (twinInput[g].GetType() == typeof(string))
  31. {
  32. strType = true;
  33. }
  34.  
  35. if (twinInput[g].GetType() == typeof(DateTime))
  36. {
  37. dtType = true;
  38. }
  39. }
  40.  
  41. if (intType)
  42. {
  43. int[] intSeq = twinInput.Select(p => (int)p).ToArray();
  44.  
  45. int temp;
  46.  
  47. for (int i = 0; i < twinInput.Length - 1; i++)
  48. {
  49. int min = i;
  50.  
  51. for (int j = i + 1; j < twinInput.Length; j++)
  52. {
  53. if (intSeq[min] > intSeq[j])
  54. {
  55. min = j;
  56. }
  57. }
  58.  
  59. if (min != i)
  60. {
  61. temp = intSeq[i];
  62. intSeq[i] = intSeq[min];
  63. intSeq[min] = temp;
  64. }
  65. }
  66.  
  67. Console.WriteLine(string.Join(" ", intSeq));
  68. }
  69.  
  70. if (strType)
  71. {
  72. string[] strSeq = twinInput.Select(p => p.ToString()).ToArray();
  73.  
  74. Array.Sort(strSeq);
  75. Console.WriteLine(string.Join(" ", strSeq));
  76. }
  77.  
  78. if (dtType)
  79. {
  80. DateTime[] dTSeq = Array.ConvertAll(twinInput, d => (DateTime)d).ToArray();
  81.  
  82. Array.Sort(dTSeq);
  83.  
  84. Console.WriteLine(string.Join(" ", dtType));
  85. }
  86.  
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement