Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            // Creation
            ILinkedList<int> testList = new LinkedList<int>() { 1, 2, 3, 4, 5};

            // Addition
            testList.Add(6);
            testList.Add(7);
            Console.WriteLine(string.Join(", ", testList)); // Enumerator

            // Removal
            testList.Remove(4);
            Console.WriteLine(string.Join(", ", testList));

            Console.WriteLine("Contains 6: " + testList.Contains(6));
            Console.WriteLine("Contains 4: " + testList.Contains(4));

            int[] arr = new int[6];
            testList.CopyTo(arr, 0);
            Console.WriteLine("Copied to array " + string.Join(", ", arr));

            testList.AddAfter(6, 13);
            Console.WriteLine("Add after result " + string.Join(", ", testList));

            testList.AddBefore(6, 13);
            Console.WriteLine("Add before result " + string.Join(", ", testList));
        }
 public void ShouldReturnAnArrayWithElementsFromListStartingFromOne()
 {
     LinkedList<int> myList = new LinkedList<int>();
     myList.Add(3);
     myList.Add(4);
     myList.Add(7);
     int[] result = new int[2];
     myList.CopyTo(result, 1);
     int[] expected = { 0, 3 };
     Assert.Equal(expected, result);
 }
 public void ShouldReturnAnArrayWithElementsFromList()
 {
     LinkedList<int> myList = new LinkedList<int>();
     myList.Add(0);
     myList.Add(4);
     myList.Add(7);
     int[] result = new int[3];
     myList.CopyTo(result,0);
     int[] expected = { 0, 4, 7 };
     Assert.Equal(expected,result);
 }
 public void ShouldRemoveFirstElementWithValueFour()
 {
     LinkedList<int> myList = new LinkedList<int>();
     myList.Add(0);
     myList.Add(4);
     myList.Add(7);
     myList.Remove(4);
     int[] expected = { 0, 7 };
     int[] result = new int[2];
     myList.CopyTo(result, 0);
     Assert.Equal(expected, result);
 }