Ejemplo n.º 1
0
        public linkedListDBL Insert(linkedListDBL head, int data)
        {
            linkedListDBL targetNode = new linkedListDBL(data);
            linkedListDBL currNode   = head;

            if (head == null)
            {
                //if head hasnt been defined, then the target node becomes the                            //first node
                head = targetNode;
            }
            else if (data < head.data)
            {
                //scenario 2:
                targetNode.next = currNode;
                head            = targetNode;
            }
            else
            {
                while (currNode.next != null && (currNode.next.data < targetNode.data))
                {
                    currNode = currNode.next;
                }
                targetNode.next = currNode.next;
                currNode.next   = targetNode;
            }
            return(head);
        }
Ejemplo n.º 2
0
        public linkedListDBL Reverse(linkedListDBL head)
        {
            linkedListDBL currNode = head;

            while (currNode != null)
            {
                linkedListDBL saveNode = currNode.prev;
                currNode.prev = currNode.next;
                currNode.next = saveNode;
                head          = currNode;
                currNode      = currNode.prev;
            }

            return(head);
        }