Exemplo n.º 1
0
        public void Delete(T value)
        {
            if (this.startNode == null)
            {
                throw new InvalidOperationException("Cannot call delete on an empty list");
            }
            else if (this.startNode.IsEqual(value))
            {
                if (this.startNode == this.lastNode)
                {
                    this.lastNode = null;
                }

                this.startNode = this.startNode.Next;
            }
            else
            {
                var node = this.startNode;
                while (node.HasNext)
                {
                    if (node.Next.IsEqual(value))
                    {
                        if (this.lastNode == node.Next)
                        {
                            this.lastNode = node;
                        }

                        node.Next = node.Next.Next;

                        return;
                    }

                    node = node.Next;
                }

                throw new InvalidOperationException("No element found to delete with value " + value);
            }
        }
Exemplo n.º 2
0
        public void AddFirst(T value)
        {
            VerifyCollectionHasRoom();

            ILinkedListNode <T> node = new LinkedListNode <T>(value);

            // If first is null than this linked list is empty and we should set First and Last to the new node.
            if (First == null)
            {
                First = node;
                Last  = node;
            }
            else
            {
                // We need to set the current First node as the next node of the current node and then set Previous
                // of the current First node to the new node.
                node.Next      = First;
                First.Previous = node;
                First          = node;
            }

            Count++;
        }
Exemplo n.º 3
0
 public RemoveLinkedListOperation <T> Remove(ILinkedListNode <T> node) => Remove <T>(node);
Exemplo n.º 4
0
 public AddBeforeLinkedListOperation <T> AddBefore(ILinkedListNode <T> node, T value) => AddBefore <T>(node, value);
Exemplo n.º 5
0
 public AddAfterLinkedListOperation <T> AddAfter(ILinkedListNode <T> node, T value) => AddAfter <T>(node, value);
Exemplo n.º 6
0
 public void AddNode(ILinkedListNode <string> node, string token)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 7
0
        public static void AssertLinkedList <TNode>(ILinkedListNode <TNode> first, ILinkedListNode <TNode> last)
            where TNode : class, ILinkedListNode <TNode>
        {
            if (first == null)
            {
                Debug.Assert(last == null);
                return;
            }

            Debug.Assert(last != null);

            if (first == last)
            {
                Debug.Assert(first.Next == null);
                Debug.Assert(last.Previous == null);
            }

            if (first.Next != null)
            {
                Debug.Assert(first.Next.Previous == first);
            }
            else
            {
                Debug.Assert(first == last);
            }

            if (last.Previous != null)
            {
                Debug.Assert(last.Previous.Next == last);
            }
            else
            {
                Debug.Assert(first == last);
            }

            {
                var nodes = new HashSet <ILinkedListNode <TNode> >();

                var prev = first;
                var curr = first.Next;

                var added = nodes.Add(prev);
                Debug.Assert(added);

                while (curr != null)
                {
                    Debug.Assert(nodes.Add(curr));
                    Debug.Assert(curr.Previous == prev);

                    prev = curr;
                    curr = curr.Next;
                }

                Debug.Assert(prev == last);
            }

            {
                var nodes = new HashSet <ILinkedListNode <TNode> >();

                var prev = last;
                var curr = last.Previous;

                var added = nodes.Add(prev);
                Debug.Assert(added);

                while (curr != null)
                {
                    Debug.Assert(nodes.Add(curr));
                    Debug.Assert(curr.Next == prev);

                    prev = curr;
                    curr = curr.Previous;
                }

                Debug.Assert(prev == first);
            }
        }
Exemplo n.º 8
0
 public void Dispose()
 {
     Next     = null;
     Previous = null;
     list     = null;
 }
Exemplo n.º 9
0
 public ILinkedList <T> AddBefore(ILinkedListNode <T> target, ILinkedListNode <T> node)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 10
0
 protected void AddHandler(MessageHandler handler)
 {
     _tail.InsertAfter(handler);
     _tail = handler;
 }
Exemplo n.º 11
0
 public Receivable()
 {
     _tail = this;
 }
Exemplo n.º 12
0
 public SinglyLinkedList()
 {
     this.startNode = null;
     this.lastNode  = null;
 }
Exemplo n.º 13
0
 public void AddNode(ILinkedListNode <IUIBinder> node, IUIBinder token)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 14
0
 public void Add(ILinkedListNode <T> node)
 {
     Next.Previous = node;
     Next          = node;
 }
Exemplo n.º 15
0
 public bool Remove(ILinkedListNode <T> node)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 16
0
 public ILinkedList <T> AddAfter(ILinkedListNode <T> target, T value)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 17
0
        public void Remove(ILinkedListNode <T> node)
        {
            var goodNode = NodeValidation(node);

            DoRemove(goodNode);
        }
Exemplo n.º 18
0
 public ILinkedList <T> Append(ILinkedListNode <T> node)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 19
0
        public void Find_Should_ReturnCorrectLinkedListNode(string[] inputItems, string itemToSearch, ILinkedListNode expectedResult)
        {
            foreach (string item in inputItems)
            {
                linkedList.Add(item);
            }
            ILinkedListNode actualResult = linkedList.Find(itemToSearch);

            Assert.Equal(expectedResult?.Value, actualResult?.Value);
        }