fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace TestArrayList
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int[] data = new int[] { 8, 9, 10, 11, 12 };
  13. int[] data2 = new int[] { 8, 9, 10, 11, 12, 13 };
  14.  
  15. Write("input1", data);
  16. Write("input2", data2);
  17.  
  18. var test1_1 = new LinkedList<int>(data);
  19. TestLinked(test1_1);
  20. var test1_2 = new LinkedList<int>(data2);
  21. TestLinked(test1_2);
  22.  
  23. Write("Test Linked_1", test1_1);
  24. Write("Test Linked_2", test1_2);
  25.  
  26. var test2_1 = new List<int>(data);
  27. TestArray(test2_1);
  28. var test2_2 = new List<int>(data2);
  29. TestArray(test2_2);
  30.  
  31. Write("Test Array_1", test2_1);
  32. Write("Test Array_2", test2_2);
  33.  
  34. TestQueue(null);
  35. }
  36.  
  37. static void Write<T>(string text, IEnumerable<T> data)
  38. {
  39. Console.WriteLine(text);
  40. foreach (var i in data)
  41. Console.Write("{0} \t", i);
  42. Console.WriteLine("\r\nEND");
  43. }
  44.  
  45.  
  46. static void TestLinked(LinkedList<int> inputOutputData)
  47. {
  48. int count = inputOutputData.Count;
  49. bool bSer = false;
  50. int iSer = count / 2;
  51. int lastCount = 0;
  52.  
  53. var current = inputOutputData.First;
  54. var currentLast = inputOutputData.Last;
  55.  
  56. for (int i = 0; i < (count-1); i++)
  57. {
  58. lastCount++;
  59. if (lastCount > iSer) bSer = true;
  60.  
  61. currentLast = currentLast.Previous;
  62. if (bSer) currentLast = currentLast.Previous;
  63. inputOutputData.AddAfter(current, currentLast.Value);
  64. current = current.Next.Next;
  65. }
  66. }
  67.  
  68. static void TestArray(List<int> inputOutputData)
  69. {
  70. int count = inputOutputData.Count;
  71. bool bSer = false;
  72. int iSer = count / 2;
  73. int lastCount = 0;
  74.  
  75. var currentI = 0;
  76. var currentLastI = count-1;
  77.  
  78. for (int i = 0; i < (count - 1); i++)
  79. {
  80. lastCount++;
  81. if (lastCount > iSer) bSer = true;
  82.  
  83. currentLastI--;
  84. if (bSer) currentLastI--;
  85. inputOutputData.Insert(currentI+1, inputOutputData[currentLastI+i]);
  86. currentI += 2;
  87. }
  88. }
  89.  
  90. static void TestQueue(Queue<int> inputOutputData)
  91. {
  92. throw new NotImplementedException("Нельзя сделать без доп. массива или контейнера");
  93. }
  94.  
  95. }
  96. }
  97.  
Runtime error #stdin #stdout #stderr 0.04s 39232KB
stdin
Standard input is empty
stdout
input1
8 	9 	10 	11 	12 	
END
input2
8 	9 	10 	11 	12 	13 	
END
Test Linked_1
8 	11 	9 	10 	10 	9 	11 	8 	12 	
END
Test Linked_2
8 	12 	9 	11 	10 	10 	11 	9 	12 	8 	13 	
END
Test Array_1
8 	11 	9 	10 	10 	9 	11 	11 	12 	
END
Test Array_2
8 	12 	9 	11 	10 	10 	11 	11 	12 	9 	13 	
END
stderr
Unhandled Exception: System.NotImplementedException: Нельзя сделать без доп. массива или контейнера
  at TestArrayList.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.NotImplementedException: Нельзя сделать без доп. массива или контейнера
  at TestArrayList.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0