public void RemoveFromListWithOnlyHead()
 {
     linkedList = new LinkedListAdt <int>();
     linkedList.AddToStart(1);
     startCount = linkedList.Count;
     linkedList.RemoveFromEnd();
 }
            public void ShouldNotBeEmptyWithValues()
            {
                var linkedList = new LinkedListAdt <int>();

                linkedList.AddToStart(1);
                linkedList.Empty().Should().BeFalse();
            }
                public void ShouldReturnException()
                {
                    var    linkedList = new LinkedListAdt <int>();
                    Action act        = () => linkedList.RemoveFromEnd();

                    act.Should().Throw <InvalidOperationException>();
                }
            public void ClearLinkedList()
            {
                linkedList = new LinkedListAdt <int>();
                linkedList.AddToStart(2);
                linkedList.AddToEnd(1);
                linkedList.AddToEnd(3);

                linkedList.Clear();
            }
                public void AddWithValuesAndTail()
                {
                    linkedList = new LinkedListAdt <int>();
                    linkedList.AddToStart(1);
                    linkedList.AddToEnd(oldTailValue);
                    oldTail = linkedList.Tail;

                    linkedList.AddToEnd(addedValue);
                }
示例#6
0
            public void SetUp()
            {
                linkedList = new LinkedListAdt <int>();
                linkedList.AddToStart(1);
                linkedList.AddToEnd(2);
                linkedList.AddToEnd(3);

                linkedList.Reverse();
            }
            public void ShouldReturnNull()
            {
                var linkedList = new LinkedListAdt <int>();

                linkedList.AddToStart(1);
                linkedList.AddToStart(2);
                linkedList.AddToStart(3);

                linkedList.SearchValue(100).Should().BeNull();
            }
                public void RemoveFromListWithHeadAndTail()
                {
                    linkedList = new LinkedListAdt <int>();
                    linkedList.AddToStart(1);
                    linkedList.AddToEnd(tailValue);
                    startCount = linkedList.Count;
                    oldTail    = linkedList.Tail;

                    linkedList.RemoveFromStart();
                }
            public void RemoveFromMiddle()
            {
                linkedList = new LinkedListAdt <int>();
                linkedList.AddToStart(1);
                linkedList.AddToEnd(2);
                linkedList.AddToEnd(3);

                startCount  = linkedList.Count;
                removedNode = linkedList.Head.Next;

                linkedList.Remove(removedNode);
            }
            public void EnumerateLinkedList()
            {
                resultList = new List <int>();
                valueList  = new List <int>();
                valueList.AddRange(new int[] { 1, 2, 3, 4 });

                var linkedList = new LinkedListAdt <int>();

                foreach (var value in valueList)
                {
                    linkedList.AddToEnd(value);
                }

                foreach (var value in linkedList)
                {
                    resultList.Add(value);
                }
            }
        public static LinkedListAdt <T> Reverse <T>(this LinkedListAdt <T> linkedList)
        {
            var current = linkedList.Head;

            while (current != null)
            {
                var temp = current.Next;

                current.Next     = current.Previous;
                current.Previous = temp;

                if (current == null)
                {
                    linkedList.Head = current;
                }
                current = temp;
            }

            return(null);
        }
 public void AddInList()
 {
     linkedList = new LinkedListAdt <int>();
     linkedList.AddToStart(oldHead);
     linkedList.AddToStart(newHead);
 }
 public void AddWithEmptyList()
 {
     linkedList = new LinkedListAdt <int>();
     linkedList.AddToStart(1);
 }
            public void ShouldStartWithCountZero()
            {
                var linkedList = new LinkedListAdt <int>();

                linkedList.Count.Should().Be(0);
            }
 public void AddToListWithHead()
 {
     linkedList = new LinkedListAdt <int>();
     linkedList.AddToStart(headValue);
     linkedList.AddToEnd(valueAdded);
 }
 public void AddToEndWithoutValues()
 {
     linkedList = new LinkedListAdt <int>();
     linkedList.AddToEnd(valueAdded);
 }