Esempio n. 1
0
        public void TestIndexator_SetItem_TooLargeIndex()
        {
            CustomLinkedList <int> list = new CustomLinkedList <int>();

            list.AddLast(1);
            list[1] = 5;
        }
Esempio n. 2
0
        public void TestIndexator_SetItem_NegativeIndex()
        {
            CustomLinkedList <int> list = new CustomLinkedList <int>();

            list.AddLast(1);
            list[-1] = 5;
        }
Esempio n. 3
0
    public static void Main()
    {
        CustomLinkedList <int> elements = new CustomLinkedList <int>();

        int count = int.Parse(Console.ReadLine());

        for (int i = 0; i < count; i++)
        {
            var    input   = Console.ReadLine().Split();
            string command = input[0];
            int    element = int.Parse(input[1]);

            switch (command)
            {
            case "Add":
                elements.Add(element);
                break;

            case "Remove":
                elements.Remove(element);
                break;
            }
        }

        Console.WriteLine(elements.Count);
        Console.WriteLine(string.Join(" ", elements));
    }
Esempio n. 4
0
        public Shop()
        {
            Product iceCream  = new Product("Ice Cream", 12);
            Product cake      = new Product("Cake", 35);
            Product chocolate = new Product("Chocolate", 24);

            Stand standWithIceCreams = new Stand(iceCream);

            standWithIceCreams.OnWorkCompleted += Stand_OnWorkCompleted;
            Stand standWithCakes = new Stand(cake);

            standWithCakes.OnWorkCompleted += Stand_OnWorkCompleted;
            Stand standWithChocolates = new Stand(chocolate);

            standWithChocolates.OnWorkCompleted += Stand_OnWorkCompleted;

            _stands = new CustomLinkedList <Stand>
            {
                standWithIceCreams,
                standWithCakes,
                standWithChocolates
            };

            _standsListLocker          = new object();
            _activeVisitorsCountLocker = new object();
            _workCompleted             = new EventWaitHandle(false, EventResetMode.ManualReset);
        }
 public void ShouldNotThrowNpeIncrementingCurrent()
 {
     var list = new CustomLinkedList<Student>();
     list++;
     list--;
     Assert.Null(list.Current);
 }
        public void ShouldThrowIndexOutOfBounds()
        {
            var linkedList = new CustomLinkedList<Student>();

            Assert.Throws<IndexOutOfRangeException>(() => { linkedList.Get(0); });
            Assert.Throws<IndexOutOfRangeException>(() => { linkedList.Get(100); });
        }
Esempio n. 7
0
        public object KthElementFromEnd <T>(CustomLinkedList <T> list, int k)
        {
            if (list == null)
            {
                return(null);
            }

            var length = list.Length();

            if (length <= 0)
            {
                return(null);
            }

            var n       = length - k;
            var current = list.GetHeadNode();

            if (n < 0)
            {
                n = length;
            }

            while (current != null)
            {
                if (n == 0)
                {
                    return(current.Data);
                }

                current = current.NextNode;
                n--;
            }

            return(null);
        }
        public void ShouldClone()
        {
            // given
            var linkedList = new CustomLinkedList<Student>();

            var student1 = new Student("F1", "L", "N", 1999);
            var student2 = new Student("F2", "L", "N", 1999);

            linkedList.PushToEnd(student1);
            linkedList.PushToEnd(student2);
            linkedList.MoveToTail();

            // when
            var clone = (CustomLinkedList<Student>) linkedList.Clone();

            // then
            Assert.False(ReferenceEquals(linkedList, clone));
            Assert.AreEqual("F2", clone.Current.FirstName);

            Assert.AreEqual(student1, clone.Get(0));
            Assert.False(ReferenceEquals(student1, clone.Get(0)));

            Assert.AreEqual(student2, clone.Get(1));
            Assert.False(ReferenceEquals(student2, clone.Get(1)));
        }
        public static CustomLinkedList <int> Rotate(CustomLinkedList <int> linkedList, int rotate)
        {
            if (linkedList == null || linkedList.Head == null)
            {
                return(null);
            }
            int counter = 1;
            var start   = linkedList.Head;

            while (counter < rotate)
            {
                start = start.Next;
                counter++;
            }

            var rotateNode = start;

            while (start.Next != null)
            {
                start = start.Next;
            }

            start.Next      = linkedList.Head;
            linkedList.Head = rotateNode.Next;
            rotateNode.Next = null;
            return(linkedList);
        }
    public static void Main()
    {
        CustomLinkedList <int> linkedList = new CustomLinkedList <int>();

        int n = int.Parse(Console.ReadLine());

        for (int i = 0; i < n; i++)
        {
            string[] cmdArgs = Console.ReadLine().Split();

            switch (cmdArgs[0])
            {
            case "Add":

                linkedList.AddToEnd(int.Parse(cmdArgs[1]));
                break;

            case "Remove":

                linkedList.Remove(int.Parse(cmdArgs[1]));
                break;
            }
        }

        Console.WriteLine(linkedList.Count);
        Console.WriteLine(string.Join(" ", linkedList));
    }
 internal Enumerator(CustomLinkedList <T> list)
 {
     this.list = list;
     node      = list.head;
     current   = default;
     index     = 0;
 }
 public void TestGetFifthElementShortList()
 {
     CustomLinkedList<DayOfWeek> list = new CustomLinkedList<DayOfWeek>();
     list.AddLast(DayOfWeek.Sunday);
     list.AddLast(DayOfWeek.Monday);
     list.GetFifthElement();
 }
Esempio n. 13
0
    static void Main(string[] args)
    {
        CustomLinkedList <string> customLinkedList = new CustomLinkedList <string>();
        int countOfCommands = int.Parse(Console.ReadLine());

        for (int i = 0; i < countOfCommands; i++)
        {
            string[] inputArgs = Console.ReadLine().Split();
            string   command   = inputArgs[0];
            string   element   = inputArgs[1];

            switch (command)
            {
            case "Add":
                customLinkedList.Add(element);
                break;

            case "Remove":
                customLinkedList.Remove(element);
                break;

            default:
                break;
            }
        }

        Console.WriteLine(customLinkedList.Count);
        foreach (var element in customLinkedList)
        {
            Console.Write($"{element} ");
        }
        Console.WriteLine();
    }
        public void RemoveElementInCustomLinkedList()
        {
            var item1 = new TestReferenceValue()
            {
                Name = "Test1"
            };
            var item2 = new TestReferenceValue()
            {
                Name = "Test2"
            };
            var item3 = new TestReferenceValue()
            {
                Name = "Test3"
            };
            CustomLinkedList <TestReferenceValue> list = new CustomLinkedList <TestReferenceValue>
            {
                item1,
                item2,
                item3
            };

            list.Remove(item2);

            int expectedCount = 2;
            TestReferenceValue expectedItem1 = item1;
            TestReferenceValue expectedItem2 = item3;

            Assert.AreEqual(expectedCount, list.Count);
            Assert.AreEqual(expectedItem1, list.First.Value);
            Assert.AreEqual(expectedItem2, list.First.NextNode.Value);
        }
Esempio n. 15
0
        static void LinkedListTest()
        {
            var linkedList = new CustomLinkedList <int>();

            linkedList.AddAtStart(1);
            linkedList.AddAtStart(5);
            linkedList.AddAtStart(6);
            linkedList.AddAtStart(5);
            linkedList.AddAtStart(2);
            linkedList.AddAtStart(2);
            linkedList.AddAtStart(5);
            linkedList.AddAtStart(1);

            System.Console.WriteLine(linkedList.Length());
            System.Console.WriteLine(linkedList.Find(1));
            System.Console.WriteLine(linkedList.ToString());

            linkedList.Reverse();

            System.Console.WriteLine(linkedList.ToString());

            // linkedList.DeleteDuplicates();

            // System.Console.WriteLine(linkedList.ToString());

            linkedList.DeleteElement(linkedList.Head);

            System.Console.WriteLine(linkedList.ToString());

            System.Console.WriteLine(linkedList.IsCircular());
        }
Esempio n. 16
0
        static void Main()
        {
            CustomLinkedList<int> customList = new CustomLinkedList<int>();

            CustomLinkedList<string> anotherList = new CustomLinkedList<string>(
                new List<string> {"pesho", "gosho", "sasho", "misho"});

            Console.WriteLine(anotherList);
            Console.WriteLine("First: " + anotherList.First.Value);
            Console.WriteLine("Last: " + anotherList.Last.Value);
            Console.WriteLine();

            customList.AddFirst(15);
            customList.AddFirst(20);
            Console.WriteLine(customList);

            customList.AddLast(50);
            customList.AddLast(100);
            Console.WriteLine(customList);

            anotherList.RemoveFirst();
            Console.WriteLine(anotherList);

            customList.RemoveLast();
            Console.WriteLine(customList);

            customList.Remove(customList.First.Next);
            Console.WriteLine(customList);

            anotherList.Clear();
            Console.WriteLine(anotherList.Count == 0 && anotherList.First == null && anotherList.Last == null);
        }
        //private static void PrintNextCar(LinkedListNode<string> car)  //This method prints after it recurses, so on the way in
        //{
        //    if (car == null) return;

        //    Write($"  {car.Data}");
        //    WriteLine($"\t({carTypes[Array.FindIndex(carTypeAbbreviations, s => s == car.Data.Substring(0, 2))]})");

        //    PrintNextCar(car.Next);
        //}

        private static void AddRailCar(CustomLinkedList <string> railcars, ref int carCount)
        {
            bool   valid = false;
            string input = "";
            int    index;
            LinkedListNode <string> newCar;

            while (!valid)
            {
                WriteLine("\nSelect a type of car to add: ");
                for (int i = 0; i < carTypePrompt.Length; i++)
                {
                    WriteLine($"- {carTypePrompt[i]} {carTypes[i]} ({carTypeAbbreviations[i]})");
                }
                Write("==> ");
                input = ReadLine();
                index = Array.FindIndex(carTypePrompt, s => s == input);    //See the comment on FindIndex in ListCars.
                if (index == -1)
                {
                    valid = false;
                    WriteLine("Invalid car type.  Again, please.");
                }
                else
                {
                    valid  = true;
                    newCar = railcars.InsertLast(new LinkedListNode <string>(carTypeAbbreviations[index] + carCount++));                        //This generates a name for the railcar:
                    //BTW, the postfix incrementer on carCount means that carCount
                    //is not incremented until AFTER the statement concludes.

                    WriteLine($"\n{carTypes[index]} {newCar.Data} successfully added to the front of the train.\n");
                }
            }
        }
        public void ShouldSortCurrentRaising()
        {
            // given
            var linkedList = new CustomLinkedList<Student>();

            for (var letter = 'A'; letter <= 'Z'; letter++)
            {
                if (letter == 'H') continue;
                linkedList.PushToEnd(StudentWithFirstName(letter.ToString()));
            }

            // when
            linkedList.PushToStart(StudentWithFirstName("H"));
            linkedList.MoveToHead();
            linkedList.SortCurrent();

            // then
            linkedList.MoveToHead();


            Console.WriteLine(linkedList);
            for (var letter = 'A'; letter <= 'Z'; letter++)
            {
                Assert.AreEqual(letter.ToString(), linkedList.Current.FirstName);
                linkedList++;
            }
        }
Esempio n. 19
0
        public void TestRandomMethods()
        {
            CustomLinkedList <int> list = new CustomLinkedList <int>();

            list.Add(1);
            list.Add(2);  // list = 1, 2

            list.Clear(); // list = null(empty)

            list.AddLast(3);
            list.AddLast(4);
            list.AddFirst(5);
            list.AddFirst(1);
            list.AddFirst(2); // list = 21534

            list.RemoveFirst();
            list.RemoveLast();
            list.RemoveAt(1);
            list.Remove(1);    // list = 3

            list.Insert(0, 1); // list = 1, 3

            Assert.AreEqual(2, list.Count);
            Assert.AreEqual(1, list[0]);
            Assert.AreEqual(3, list[1]);
        }
Esempio n. 20
0
    static void Main(string[] args)
    {
        CustomLinkedList<int> customLinkedList = new CustomLinkedList<int>();

        customLinkedList.Add(5);
        customLinkedList.Add(4);
        customLinkedList.Add(2);
        customLinkedList.Add(3);
        customLinkedList.Add(4);
        customLinkedList.Add(5);

        Console.WriteLine(customLinkedList.Count);
        Console.WriteLine(customLinkedList.FirstIndexOf(4));
        Console.WriteLine(customLinkedList.LastIndexOf(4));
        customLinkedList.Remove(0);
        customLinkedList.Remove(customLinkedList.Count - 1);
        customLinkedList.Remove(1);

        Console.WriteLine();

        for (int i = 0; i < customLinkedList.Count; i++)
        {
            Console.WriteLine(customLinkedList[i]);
        }

        Console.WriteLine();

        foreach(var item in customLinkedList)
        {
            Console.WriteLine(item);
        }
    }
Esempio n. 21
0
    static void Main(string[] args)
    {
        CustomLinkedList <int> customLinkedList = new CustomLinkedList <int>();

        customLinkedList.Add(5);
        customLinkedList.Add(4);
        customLinkedList.Add(2);
        customLinkedList.Add(3);
        customLinkedList.Add(4);
        customLinkedList.Add(5);

        Console.WriteLine(customLinkedList.Count);
        Console.WriteLine(customLinkedList.FirstIndexOf(4));
        Console.WriteLine(customLinkedList.LastIndexOf(4));
        customLinkedList.Remove(0);
        customLinkedList.Remove(customLinkedList.Count - 1);
        customLinkedList.Remove(1);

        Console.WriteLine();

        for (int i = 0; i < customLinkedList.Count; i++)
        {
            Console.WriteLine(customLinkedList[i]);
        }

        Console.WriteLine();

        foreach (var item in customLinkedList)
        {
            Console.WriteLine(item);
        }
    }
Esempio n. 22
0
        public void TestRemove_ListIsEmpty()
        {
            CustomLinkedList <int> list = new CustomLinkedList <int>();

            bool removed = list.Remove(0);

            Assert.IsFalse(removed);
        }
Esempio n. 23
0
        public void TestIndexator_GetItem_TooLargeIndex()
        {
            CustomLinkedList <int> list = new CustomLinkedList <int>();

            list.AddFirst(1);

            Assert.AreEqual(1, list[1]);
        }
Esempio n. 24
0
        private static void RotateLeft(CustomLinkedList <int> linkedList, int position)
        {
            if (position == 0)
            {
                return;
            }

            // Let us understand the below
            // code for example k = 4
            // and list = 10->20->30->40->50->60.
            LinkedNode <int> current = linkedList.Head;

            // current will either point to kth
            // or NULL after this loop. current
            // will point to node 40 in the above example
            int count = 1;

            while (count < position && current.Next != null)
            {
                current = current.Next;
                count++;
            }

            // If current is NULL, k is greater than
            // or equal to count of nodes in linked list.
            // Don't change the list in this case
            if (current == null)
            {
                return;
            }

            // current points to kth node.
            // Store it in a variable.
            // kthNode points to node
            // 40 in the above example
            LinkedNode <int> kthNode = current;

            // current will point to
            // last node after this loop
            // current will point to
            // node 60 in the above example
            while (current.Next != null)
            {
                current = current.Next;
            }

            // Change next of last node to previous head
            // Next of 60 is now changed to node 10

            current.Next = linkedList.Head;

            // Change head to (k+1)th node
            // head is now changed to node 50
            linkedList.Head = kthNode.Next;

            // change next of kth node to null
            kthNode.Next = null;
        }
Esempio n. 25
0
        public LinkedListTests()
        {
            _list = new CustomLinkedList();

            _list.AddSorted(new ListNode(2));
            _list.AddSorted(new ListNode(4));
            _list.AddSorted(new ListNode(3));
            _list.AddSorted(new ListNode(1));
        }
Esempio n. 26
0
        public void LinkedListAddElementsCorrectly()
        {
            var list = new CustomLinkedList <int>();

            list.Add(2);
            list.Add(5);
            list.Add(4);
            Assert.Equal(3, list.Count);
        }
Esempio n. 27
0
        static void Main()
        {
            CustomLinkedList<int> list = new CustomLinkedList<int>();
            list.AddFirst(5);
            list.AddFirst(1);
            list.AddFirst(11);

            Console.WriteLine(list.Count);
        }
        public void ShouldCompareBySize()
        {
            var a = new CustomLinkedList<Student>();
            var b = new CustomLinkedList<Student>();

            a.PushToEnd(StudentWithFirstName("H"));

            Assert.AreEqual(-1, a.CompareTo(b));
        }
 public void TestCount()
 {
     CustomLinkedList<char> list = new CustomLinkedList<char>();
     list.AddLast('a');
     list.AddLast('b');
     list.AddLast('c');
     list.AddFirst('z');
     Assert.AreEqual(4,list.Count);
 }
 public void TestGetItemAt()
 {
     CustomLinkedList<DayOfWeek> list = new CustomLinkedList<DayOfWeek>();
     list.AddLast(DayOfWeek.Monday);
     list.AddFirst(DayOfWeek.Sunday);
     list.AddLast(DayOfWeek.Tuesday);
     list.AddLast(DayOfWeek.Wednesday);
     Assert.AreEqual( DayOfWeek.Tuesday,list.GetItemAt(2).Data);
 }
Esempio n. 31
0
        public void LinkedListContainsShouldReturnFalseIfElementNotExistsInList()
        {
            var list = new CustomLinkedList <int>();

            list.Add(2);
            list.Add(5);
            list.Add(9);

            Assert.False(list.Contains(11));
        }
Esempio n. 32
0
        public void TestRemoveAt_ListHasOnlyOneItem()
        {
            CustomLinkedList <int> list = new CustomLinkedList <int>();

            list.Add(1);

            list.RemoveAt(0);

            Assert.AreEqual(0, list.Count);
        }
 public void TestAddLast()
 {
     CustomLinkedList<char> list = new CustomLinkedList<char>();
     list.AddLast('a');
     Assert.AreEqual('a', list.Head.Data);
     Assert.AreEqual('a', list.Tail.Data);
     list.AddLast('b');
     list.AddLast('c');
     Assert.AreEqual("a->b->c", list.ToString());
 }
Esempio n. 34
0
        public void TestIndexOf_Found_MustReturn2()
        {
            CustomLinkedList <int> list = new CustomLinkedList <int>();

            list.AddLast(1);
            list.AddLast(2);
            list.AddLast(3);

            Assert.AreEqual(2, list.IndexOf(3));
        }
 public void TestAddFirst()
 {
     CustomLinkedList<int> list = new CustomLinkedList<int>();
     list.AddFirst(1);
     Assert.AreEqual(1, list.Head.Data);
     Assert.AreEqual(1, list.Tail.Data);
     list.AddFirst(2);
     list.AddFirst(3);
     Assert.AreEqual("3->2->1", list.ToString());
 }
Esempio n. 36
0
        public void TestIndexOf_NotFound()
        {
            CustomLinkedList <int> list = new CustomLinkedList <int>();

            list.AddLast(1);
            list.AddLast(2);
            list.AddLast(3);

            Assert.AreEqual(-1, list.IndexOf(4));
        }
Esempio n. 37
0
        public void Array_Of_Values_Are_Equal(string[] values)
        {
            _customList = new CustomLinkedList();
            foreach (var value in values)
            {
                _customList.Append(value);
            }

            Assert.IsTrue(Enumerable.SequenceEqual(values, _customList.GetAllValues()));
        }
        public void CreateNode_Test()
        {
            CustomLinkedList<int> instI = new CustomLinkedList<int>();

            instI.Add(300);
            instI.Add(500);
            instI.Add(85);
            instI.Add(85);

            Assert.AreEqual(3, instI.Count);
        }
        public void TestCustomLinkedListAdd(string[] incomeArray, string[] resultArray)
        {
            var lList = new CustomLinkedList <string>();

            foreach (var item in incomeArray)
            {
                lList.Add(item);
            }

            Assert.IsTrue(CheckListAndArrayValues(lList, resultArray));
        }
 public void TestGetFifthElement()
 {
     CustomLinkedList<DayOfWeek> list = new CustomLinkedList<DayOfWeek>();
     list.AddLast(DayOfWeek.Sunday);
     list.AddLast(DayOfWeek.Monday);
     list.AddLast(DayOfWeek.Tuesday);
     list.AddLast(DayOfWeek.Wednesday);
     list.AddLast(DayOfWeek.Thursday);
     list.AddLast(DayOfWeek.Friday);
     list.AddLast(DayOfWeek.Saturday);
     Assert.AreEqual(DayOfWeek.Tuesday,list.GetFifthElement().Data);
 }
        public void CustomLinkedList_AddFirstTest()
        {
            CustomLinkedList<int> myLink = new CustomLinkedList<int>();

            for (int i = 0; i < 10; i++)
            {
                myLink.AddFirst(i);
            }

            int expected = 10;

            Assert.AreEqual(expected, myLink.Count);
        }
        public static void Main(string[] args)
        {
            CustomLinkedList<int> list = new CustomLinkedList<int>();

            list.AddFirst(5);
            list.AddFirst(6);
            list.AddLast(10);
            list.AddLast(50);
            list.AddFirst(4);

            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine(list[i]);
            }
        }
        public void CreateNode_Foreach_Test()
        {
            CustomLinkedList<int> instI = new CustomLinkedList<int>();
            instI.Add(300);
            instI.Add(500);
            instI.Add(85);
            instI.Add(85);

            int count = 0;
            foreach (var item in instI)
            {
                count++;
            }
            Assert.AreEqual(3, count);
        }
        public void CustomLinkedList_ClearTest()
        {
            CustomLinkedList<int> myLink = new CustomLinkedList<int>();

            for (int i = 0; i < 10; i++)
            {
                myLink.AddLast(i);
            }

            myLink.Clear();

            int expected = 0;

            Assert.AreEqual(expected, myLink.Count);
        }
Esempio n. 45
0
        public static void Main(string[] args)
        {
            var linkedList = new CustomLinkedList<int>();

            linkedList.AddItem(1);
            linkedList.AddFirst(2);
            linkedList.AddItem(3);
            linkedList.AddItem(4);
            Console.WriteLine(linkedList);

            linkedList.RemoveItem(3);
            Console.WriteLine(linkedList);

            linkedList.RemoveFirst();
            Console.WriteLine(linkedList);
        }
        public void CustomLinkedList_RemoveLastTest()
        {
            CustomLinkedList<int> myLink = new CustomLinkedList<int>();

            for (int i = 0; i < 10; i++)
            {
                myLink.AddLast(i);
            }

            for (int i = 0; i < 5; i++)
            {
                myLink.RemoveLast();
            }

            int expected = 5;

            Assert.AreEqual(expected, myLink.Count);
        }
Esempio n. 47
0
    static void Main(string[] args)
    {
        CustomLinkedList<int> customList = new CustomLinkedList<int>();
        customList.AddLast(15);
        customList.AddLast(30);
        customList.AddLast(31);
        customList.AddLast(32);
        customList.AddLast(33);

        Console.WriteLine(customList.FirstItem.Value);
        Console.WriteLine(customList.FirstItem.NextItem.Value);
        Console.WriteLine(customList.Count);

        customList.RemoveLast();
        Console.WriteLine(customList.Count);
        customList.RemoveLast();
        Console.WriteLine(customList.Count);
        customList.RemoveLast();
        Console.WriteLine(customList.Count);
    }
Esempio n. 48
0
        static void Main(string[] args)
        {
            CustomLinkedList<int> newList = new CustomLinkedList<int>();
            newList.Add(1);
            var specificNode = newList.Add(2);
            newList.Add(3);
            newList.Add(4);

            newList.AddAfter(specificNode,9);
            Console.Write("Whole List: ");
            newList.ForEach(x => Console.Write(x + " "));
            Console.WriteLine();
            Console.WriteLine("Head is: " +newList.Head.Value);
            Console.WriteLine("Tail is: " + newList.Tail.Value);
            foreach (var i in newList)
            {
                Console.Write(i +" ");
            }
            Console.WriteLine();
            Console.WriteLine("First index of 9 is: " + newList.FirstIndexOf(9));
        }
        public void Remove(int startIndex, int numCharsToRemove)
        {
            CustomLinkedList<char> newString = new CustomLinkedList<char>();
            int i = 0;
            for (CustomLinkedListNode<char> current = _string.First; current != null; current = current.Next)
            {
                if (i == startIndex)
                {
                    int j = numCharsToRemove;
                    while (j > 0)
                    {
                        current = current?.Next;
                        j--;
                    }

                }
                newString.AddLast(current.Value);
                i++;
            }
            _string = newString;
        }
Esempio n. 50
0
        public static void Main()
        {
            LinkedList<int> test = new LinkedList<int>();

            CustomLinkedList<int> myLink = new CustomLinkedList<int>();
            myLink.AddFirst(2);
            myLink.RemoveFirst();

            for (int i = 0; i < 10; i++)
            {
                myLink.AddFirst(i);
            }

            myLink.AddLast(123);
            myLink.RemoveFirst();
            myLink.RemoveFirst();

            Console.WriteLine(myLink.Count);

            Console.WriteLine();
        }
 public void Insert(int index, string stringToInsert)
 {
     int i = 0;
     if (index == _string.Count)
     {
         _string = _string.Concat(new CustomLinkedList<char>(stringToInsert.ToList()));
         return;
     }
     for (CustomLinkedListNode<char> current = _string.First; current != null; current = current.Next)
     {
         if (i == index)
         {
             CustomLinkedList<char> insertString = new CustomLinkedList<char>(stringToInsert.ToList());
             //_string.AddAfter(current, insertString.First);
             for (CustomLinkedListNode<char> node = insertString.First; node != null; node = node.Next)
             {
                 _string.AddBefore(current, node.Value);
             }
         }
         i++;
     }
 }
        static void Main()
        {
            var testList = new CustomLinkedList<string>();
            testList.Add("First");
            testList.Add("Last");
            testList.AddFirst("New first");
            testList.AddLast("New last");

            Console.WriteLine("Linked list contents: {0}\n", string.Join(" --> ", testList));

            testList.RemoveFirst();
            testList.RemoveLast();

            Console.WriteLine("After removing New First and New Last: ");
            Console.WriteLine("Linked list contents: {0}\n", string.Join(" --> ", testList));

            testList.Add("Some value");
            testList.Remove("Last");

            Console.WriteLine("After adding Some value and removing Last by value: ");
            Console.WriteLine("Linked list contents: {0}\n", string.Join(" --> ", testList));
        }
        public static void Main()
        {
            CustomLinkedList<int> testList = new CustomLinkedList<int>();

            for (int i = 1; i < 25; i++)
            {
                testList.AddFirst(i);
            }

            for (int i = 1; i < 25; i++)
            {
                testList.AddLast(i);
            }

            Console.WriteLine(testList.Count);

            for (int i = 0; i < testList.Count; i++)
            {
                Console.Write("{0} ", testList[i]);
            }

            Console.WriteLine();
            Console.WriteLine("Demonstration without 1");
            testList.Remove(1);

            for (int i = 0; i < testList.Count; i++)
            {
                Console.Write("{0} ", testList[i]);
            }

            Console.Write("The sequence contains 2: {0}",testList.Contains(2));

            testList.Clear();

            Console.WriteLine();
        }
 public void TestRemoveFromTail()
 {
     CustomLinkedList<float> list = new CustomLinkedList<float>();
     list.AddLast(1.1f);
     list.AddFirst(1.0f);
     list.AddFirst(1.2f);
     list.AddLast(1.3f);
     Assert.AreEqual("1.2->1->1.1->1.3", list.ToString());
     Assert.AreEqual( 1.3f,list.RemoveFromTail().Data);
     Assert.AreEqual( "1.2->1->1.1",list.ToString());
 }
 public void TestIsValid()
 {
     CustomLinkedList<DayOfWeek> list = new CustomLinkedList<DayOfWeek>();
     list.AddLast(DayOfWeek.Sunday);
     list.AddLast(DayOfWeek.Monday);
     list.AddLast(DayOfWeek.Tuesday);
     list.AddLast(DayOfWeek.Wednesday);
     list.AddLast(DayOfWeek.Thursday);
     list.AddLast(DayOfWeek.Friday);
     list.AddLast(DayOfWeek.Saturday);
     Assert.AreEqual(true, list.IsValid());
     //Create a loop
     list.Tail.Next = list.Head;
     Assert.AreEqual(false, list.IsValid());
 }
 public CustomLinkedListString(string s)
 {
     _string = new CustomLinkedList<char>(s.ToList());
 }
 public void TestRemoveFromHead()
 {
     CustomLinkedList<string> list = new CustomLinkedList<string>();
     list.AddLast("John");
     list.AddFirst("Peter");
     list.AddLast("Paul");
     list.AddLast("Brown");
     Assert.AreEqual("Peter->John->Paul->Brown", list.ToString());
     Assert.AreEqual("Peter",list.RemoveFromHead().Data);
     Assert.AreEqual("John->Paul->Brown",list.ToString());
 }
 public void TestGetItemAtInvalidIndex()
 {
     CustomLinkedList<DayOfWeek> list = new CustomLinkedList<DayOfWeek>();
     list.AddLast(DayOfWeek.Sunday);
     list.AddLast(DayOfWeek.Monday);
     list.GetItemAt(-1);
 }
 public void TestRemoveFromTailEmpty()
 {
     CustomLinkedList<DayOfWeek> list = new CustomLinkedList<DayOfWeek>();
     list.RemoveFromTail();
 }
 public void TestTail()
 {
     CustomLinkedList<string> list = new CustomLinkedList<string>();
     Assert.AreEqual(null, list.Tail);
     list.AddLast("John");
     list.AddFirst("Peter");
     list.AddLast("Paul");
     Assert.AreEqual("Paul", list.Tail.Data);
 }