Ejemplo n.º 1
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++;
        }
Ejemplo n.º 2
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());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a new node containing the data provided to the linked list at the tail
        /// </summary>
        /// <param name="data">The data to add</param>
        private void LinkTail(T data)
        {
            Node <T> toAdd = new Node <T>(data, tail, null);

            // Not in diagram
            tail.SetNext(toAdd);

            tail = toAdd;

            size++;
        }
        public void TestSetNext()
        {
            Employee        emp1     = new Employee(1);
            Employee        emp2     = new Employee(2);
            Employee        emp3     = new Employee(3);
            Node <Employee> node1    = new Node <Employee>(emp1);
            Node <Employee> node2    = new Node <Employee>(emp2);
            Node <Employee> testNode = new Node <Employee>(emp3, node1, null);

            testNode.SetNext(node2);
            Assert.That(testNode.GetNext(), Is.EqualTo(node2));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Remove the node at the tail of the linked list and return the data it contains
        /// </summary>
        /// <returns>The data stored in the node being removed</returns>
        private T UnlinkTail()
        {
            Node <T> oldTail = tail;

            tail = tail.GetPrevious();

            tail.SetNext(null);

            size--;

            return(oldTail.GetData());
        }
Ejemplo n.º 6
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++;
        }