示例#1
0
        public void HeadRemove_RemoveHeadNode_HeadNodeIsRemoved()
        {
            var uut = new MyLinkedList();
            uut.HeadInsert(1);
            uut.HeadRemove();

            Assert.IsTrue(uut.IsEmpty());
        }
示例#2
0
        static void Main(string[] args)
        {
            MyLinkedList <int> linkedList = new MyLinkedList <int>();

            linkedList.Add(1);
            linkedList.Add(2);
            linkedList.Add(3);
            linkedList.AddToStart(4);
            WriteList(linkedList);
            Console.WriteLine(linkedList.Count);
            Console.WriteLine(linkedList.Contains(4));
            Console.WriteLine(linkedList.Contains(5));
            Console.WriteLine(linkedList.IndexOf(2));
            Console.WriteLine(linkedList.IndexOf(5));
            Console.ReadKey();
        }
示例#3
0
        public MyLinkedList AddLists(MyLinkedList list1, MyLinkedList list2)
        {
            var summedUpList = new MyLinkedList();
            var carryOver    = 0;
            var node1        = list1._head;
            var node2        = list2._head;

            while (node1 != null && node2 != null)
            {
                var sum = node1.Value + node2.Value + carryOver;
                carryOver = sum >= 10 ? 1 : 0;
                summedUpList.AddToTail(new Node(sum % 10));

                node1 = node1.Next;
                node2 = node2.Next;
            }
            return(summedUpList);
        }
        static void Main(string[] args)
        {
            // can grow and shrink automatically
            // each node holds 2 pieces a data: value and the address of the next node in the list
            // first node: head. last node: tail
            // lookup by value: O(n), by index: O(n)
            // insert at the end: O(1), at beginning O(1). Just reference the new head or tail
            // in the middle: O(n)
            // delete: beginning O(1). end and middle: O(n)

            var linkedList = new LinkedList <int>();

            var myLinkedList = new MyLinkedList();

            myLinkedList.AddLast(10);
            myLinkedList.AddLast(20);
            myLinkedList.AddLast(30);

            myLinkedList.Reverse();
        }
 public MyLinkedListEnumerator(MyLinkedList <T> list)
 {
     _list = list;
     Reset();
 }
示例#6
0
 public void IsEmpty_ListIsNotEmpty_ReturnFalse()
 {
     var uut = new MyLinkedList();
     uut.HeadInsert(1);
     Assert.IsFalse(uut.IsEmpty());
 }
示例#7
0
        public void IsEmpty_ListIsEmpty_ReturnTrue()
        {
            var uut = new MyLinkedList();

            Assert.IsTrue(uut.IsEmpty());
        }
示例#8
0
 public void HeadInsert_InsertNewNodeAtHeadOfListWithDataX_DataXIsInsertedAtHeadOfList()
 {
     var uut = new MyLinkedList();
     uut.HeadInsert(1);
     Assert.IsFalse(uut.IsEmpty());
 }