// copy constructor
DoublyLinkedList::DoublyLinkedList(const DoublyLinkedList& dll)
{
  // Initialize the list
  header.next = &trailer; trailer.prev = &header;
  DListNode *p, *node = header.next;
 
  // remove old list
  if (header.next != &trailer)
  {
      while (node->next != 0) 
      {
        p = node;
        node = node->next;
        delete p;
      }
  }
  cout<<"List Deleted"<<endl;
     
      // create a new list
      node = dll.getFirst();
      while (node != dll.getAfterLast()) 
      {
        this->insertLast(node->getElem());
        node = node->next;
      }
}
// return the list length
int DoublyLinkedListLength(DoublyLinkedList& dll) {  //O(n)
  DListNode *current = dll.getFirst();
  int count = 0;
  while(current != dll.getAfterLast()) {
    count++;
    current = current->getNext(); //iterate
  }
  return count;
}
// copy constructor
DoublyLinkedList::DoublyLinkedList(const DoublyLinkedList& dll)  //O(n)
{
  // Initialize the list
  header.next = &trailer; trailer.prev = &header;
  
  DListNode *current = dll.getFirst();
  while(current != dll.getAfterLast())
	{
	  insertFirst(current->getElem());
	  current=current->getNext();
	}
  
}
// copy constructor
DoublyLinkedList::DoublyLinkedList(DoublyLinkedList& dll)
{
  // Initialize the list
  header.next = &trailer; trailer.prev = &header;
  if (!dll.isEmpty()){
  DListNode* node;
  node=dll.getFirst();
  while (node!=dll.getAfterLast()){
    insertLast(node->getElem());//insert new element
    node=node->getNext();//set node to next node
 }
}
}