title: C++ Deep Copying Linked List
body: <p>First of all, this is part of an assignment I'm currently trying to figure out. I'm trying to create a copy constructor that deep copies a given LinkedList.
  I have coded the LinkedList methods already.</p>
  
  <p>Here's the necessary parts of the LinkedList.h file.</p>
  
  <pre><code>LinkedList.h
  private:
      struct node {
          Val data;
          node* next = nullptr;
  
      };
  
      typedef struct node* nodePtr;
  
  
      nodePtr head = nullptr;
      nodePtr current = nullptr;
      nodePtr temp = nullptr;
  };
  </code></pre>
  
  <p>The parameters are given: "LinkedList::LinkedList(const LinkedList &amp; ll)"
  ll is the linked list to be copied.
  I first tested if there is a head in the linked list, if not then that means the linked list is empty.
  Then I copied the head from the old list to the new list.
  I then set the new current to the head in preparation for the while loop.
  Inside the while loop, I am copying the data of the current node as well as the pointer to the next node.
  At the end I set the next pointer to nullptr to signify the end of the new list.</p>
  
  <pre><code>LinkedList.cpp
  
  LinkedList::LinkedList(const LinkedList &amp; ll){
      if (ll.head == nullptr) {
          return;
      }
      head = ll.head;
      current = head;
  
  
      while (ll.current-&gt;next != nullptr) {
          current-&gt;data = ll.current-&gt;data;
          current-&gt;next = ll.current-&gt;next;
      }
      current-&gt;next = nullptr;
  }
  </code></pre>
  
  <p>I'm not sure if this is deep copying or not.
  I also know that ll.current's starting position is not at the head.
  I tried ll.current = ll.head. However, since it is given that this function is const. I can't set it like that.</p>
  
  <p>There is also another function given:
      LinkedList &amp; LinkedList::operator=(const LinkedList &amp; ll)
      {
      }
  That I suspect may be needed. I'm hoping it optional that I use this.</p>