Esempio n. 1
0
        public LinkedList(LinkedList <Type> listToCopy) // Copy
        {
            LinkedListNode <Type> thisWorkingNode, thatWorkingNode = listToCopy.GetHead();

            head = null;
            tail = null;

            if (thatWorkingNode != null)
            {
                head            = new LinkedListNode <Type>(thatWorkingNode);
                thisWorkingNode = head;

                thatWorkingNode = thatWorkingNode.GetNext();

                while (thatWorkingNode != null)
                {
                    thisWorkingNode.SetNext(new LinkedListNode <Type>(thatWorkingNode));
                    tail = thisWorkingNode.GetNext();
                    tail.SetPrev(thisWorkingNode.GetPrev());

                    thisWorkingNode = thisWorkingNode.GetNext();
                    thatWorkingNode = thatWorkingNode.GetNext();
                    tail            = thatWorkingNode;
                }
            }
        }
Esempio n. 2
0
        private void UpdateTail(LinkedListNode <Type> inNode)
        {
            LinkedListNode <Type> workingNode = inNode;

            while (workingNode.GetNext() != null)
            {
                workingNode = workingNode.GetNext();
            }

            tail = workingNode;
        }
Esempio n. 3
0
        public Type Remove(Type target)
        {
            LinkedListNode <Type> workingNode, nodeToRemove = SearchList(target);

            workingNode = nodeToRemove.GetPrev();
            workingNode.SetNext(nodeToRemove.GetNext());

            workingNode = workingNode.GetNext();
            workingNode.SetPrev(nodeToRemove.GetPrev());

            UpdateTail(workingNode);

            return(nodeToRemove.GetData());
        }
Esempio n. 4
0
        public void DisplayList()
        {
            LinkedListNode <Type> workingNode = head;

            Console.WriteLine("<List Name>:");

            while (workingNode != null)
            {
                Console.WriteLine(workingNode.ToString());
                workingNode = workingNode.GetNext();
            }

            Console.WriteLine("Head: " + head);
            Console.WriteLine("Tail: " + tail);
        }
Esempio n. 5
0
        private LinkedListNode <Type> SearchList(Type target)
        {
            LinkedListNode <Type> workingNode;

            if (head.Equals(target))
            {
                return(head);
            }
            else
            {
                workingNode = head.GetNext();

                while (!workingNode.Equals(target))
                {
                    workingNode = workingNode.GetNext();
                }

                return(workingNode);
            }
        }