public void TestSetPrevious()
        {
            Employee        emp1  = new Employee(1);
            Employee        emp2  = new Employee(2);
            Node <Employee> node1 = new Node <Employee>(emp1);
            Node <Employee> node2 = new Node <Employee>(emp2);

            node2.SetPrevious(node1);
            Assert.That(node2.GetPrevious(), Is.EqualTo(node1));
        }
Example #2
0
        /// <summary>
        /// Adds the data to a new node in the linked list between the nodes specified
        /// </summary>
        /// <param name="data">Data to add to the list</param>
        /// <param name="previous">A pointer to the node that will come before data's node</param>
        /// <param name="next">A pointer to the node that will come after the data's node</param>
        private void Link(T data, Node <T> previous, Node <T> next)
        {
            Node <T> newNode = new Node <T>(data, previous, next);

            previous.SetNext(newNode);

            next.SetPrevious(newNode);

            size++;
        }
Example #3
0
        /// <summary>
        /// Removes the specified node from the linked list
        /// </summary>
        /// <param name="node">The node to be removed</param>
        /// <returns>Data from the node being removed</returns>
        private T Unlink(Node <T> node)
        {
            Node <T> previous = node.GetPrevious();
            Node <T> next     = node.GetNext();

            previous.SetNext(next);
            next.SetPrevious(previous);
            size--;

            return(node.GetData());
        }
Example #4
0
        /// <summary>
        /// Removes the node at the head of the linked list and returns the data it contains
        /// </summary>
        /// <returns>The data from the unlinked head node</returns>
        private T UnlinkHead()
        {
            Node <T> oldHead = head;
            T        data;

            head = head.GetNext();

            size -= 1;

            // Determine if head is now null and if it is make the tail null as well
            if (head == null)
            {
                tail = null;
            }

            head?.SetPrevious(null);

            data = oldHead.GetData();

            return(data);
        }
Example #5
0
        /// <summary>
        /// Adds the node to the head when null if not adds it after the head
        /// </summary>
        /// <param name="data">The node to be added</param>
        private void LinkHead(T data)
        {
            Node <T> toAdd = new Node <T>(data);

            // Determine if the head is null
            if (head != null)
            {
                head.SetPrevious(toAdd);
                toAdd.SetNext(head);
            }

            head = toAdd;


            // Determine if the linked list is empty and make the tail also the head
            if (size == 0)
            {
                tail = head;
            }

            size++;
        }