Ejemplo n.º 1
0
        public void PushToHead(T data)
        {
            //Allocate new node
            DllNode <T> newNode = new DllNode <T>(data);

            this.PushToHead(newNode);
        }
Ejemplo n.º 2
0
        public void Print()
        {
            DllNode <T> current = Head;

            while (current != null)
            {
                Console.Write(current.Data);
                Console.Write("->");
                current = current.Next;
            }
            Console.WriteLine();
        }
Ejemplo n.º 3
0
        public void PushToHead(DllNode <T> newNode)
        {
            //Append whole list behind new node
            newNode.Next = Head;

            if (this.Tail == null)
            {
                this.Tail = newNode;
            }

            if (Head != null)
            {
                Head.Prev = newNode;
            }

            //Make new node as head of the list
            Head = newNode;
        }
Ejemplo n.º 4
0
        public DllNode <T> DeleteNode(DllNode <T> node)
        {
            DllNode <T> prevNode = node.Prev;
            DllNode <T> nextNode = node.Next;

            if (prevNode == null) //node to be deleted is head
            {
                this.Head = null;
            }
            else
            {
                prevNode.Next = nextNode;
            }

            if (nextNode != null) // node to be deleted is not last node
            {
                nextNode.Prev = prevNode;
            }
            else //if(nextNode==null) //node to be deleted is last node
            {
                this.Tail = null;
            }
            return(node);
        }
 public DllNode(T data)
     : base(data)
 {
     this.Prev = null;
     this.Next = null;
 }
Ejemplo n.º 6
0
 public DoublyLinkedList(DllNode <T> someHeadOfOtherList, DllNode <T> tailOfOtherList)
 {
     this.Head = someHeadOfOtherList;
     this.Tail = tailOfOtherList;
 }
Ejemplo n.º 7
0
 public DoublyLinkedList()
 {
     this.Head = null;
     this.Tail = null;
 }