title: Run Time Error with a Doubly Linked List
body: <p>So, I've tried to implement a doubly linked list in C++.
  It compiles just fine, but the moment it runs, it crashes and exits. 
  It just says "Process returned -1073741819"</p>
  
  <p>(I'm using Code::Blocks and the GNU GCC Compiler btw)</p>
  
  <p>I have a feeling that the problem lies in the constructor, but I'm not exactly sure. I've tried experimenting around with it, but to no avail.</p>
  
  <p>Any ideas what might be spawning the run time error? Any pointers (no pun intended) to what might trigger the issue will be greatly appreciated!</p>
  
  <p>DNode.h</p>
  
  <pre><code>#ifndef DNODE_H_INCLUDED
  #define DNODE_H_INCLUDED
  #include &lt;stdio.h&gt;
  #include &lt;ostream&gt;
  
  class DNode{
  
  private:
      int elem;
      DNode* next;
      DNode* prev;
      friend class DList;
  public:
      DNode(int value=0){
          elem= value;
          next= NULL;
          prev = NULL;
      }
  };
  
  
  #endif // DNODE_H_INCLUDED
  </code></pre>
  
  <p>DList.h</p>
  
  <pre><code>#ifndef DLIST_H_INCLUDED
  #define DLIST_H_INCLUDED
  #include "DNode.h"
  
  using namespace std;
  
  class DList{
  
  private:
      DNode* head;
      DNode* tail;
  
  public:
      DList(){
          head = NULL;
          tail = NULL;
      }
      ~DList();
      void display();
      bool isEmpty() const;
      const int&amp; getFront() const;
      const int&amp; getRear() const;
      void addFront(const int&amp; e);
      void addRear(const int&amp; e);
      void removeFront();
      void removeRear();
      void addMiddleBefore(const int&amp;e, const int&amp; pos);
      void addMiddleAfter(const int&amp;e, const int&amp; pos);
      bool isIn(const int&amp; e);
      void removeNode(const int&amp; e);
  
  };
  
  
  
  
  #endif // DLIST_H_INCLUDED
  </code></pre>
  
  <p>DList.cpp</p>
  
  <pre><code>#include "DList.h"
  #include "DNode.h"
  #include &lt;iostream&gt;
  
  using namespace std;
  
  void DList::display(){
  DNode* cur = head;
  while((cur-&gt;next) != tail){
      cout&lt;&lt;cur-&gt;elem&lt;&lt;"-&gt;";
      cur = cur -&gt; next;
  }
  cout&lt;&lt;endl;
  }
  
  
  bool DList::isEmpty()const {
  DNode* cur = head;
  if((cur-&gt;next) = tail){
      cout&lt;&lt;"Yep, the list is empty!"&lt;&lt;endl;
      return true;
  }
  else{
      cout&lt;&lt;"Nope,not empty"&lt;&lt;endl;
      return false;
  }
  }
  
  const int&amp; DList::getFront() const{
  cout&lt;&lt;"The first element is " &lt;&lt;endl;
  return head-&gt;elem;
  }
  
  const int&amp; DList::getRear() const{
  cout&lt;&lt;"The last element is "&lt;&lt;endl;
  return tail-&gt;elem;
  }
  
  void DList::addFront(const int&amp; e){
  DNode* temp = new DNode(e);
  DNode* cur = head;
  
  temp-&gt;next = cur-&gt;next;
  temp-&gt;prev = cur;
  cur-&gt;next-&gt;prev = temp;
  cur-&gt;next = temp;
  cout&lt;&lt;"Added element to the front"&lt;&lt;endl;
  }
  
  
  void DList::addRear(const int&amp; e){
  DNode* temp = new DNode(e);
  DNode* cur = tail;
  
  temp-&gt;next = cur;
  temp-&gt;prev = cur-&gt;prev;
  cur-&gt;prev-&gt;next = temp;
  cur-&gt;prev = temp;
  cout&lt;&lt;"Added element to the rear"&lt;&lt;endl;
  }
  
  void DList::addMiddleBefore(const int&amp;e, const int&amp; pos){
  DNode*temp = new DNode(e);
  DNode *cur = head;
  
  while((cur-&gt;elem) != pos ){
      cur = cur -&gt; next;
  }
  temp-&gt;next = cur;
  temp-&gt;prev = cur-&gt;prev;
  cur-&gt;prev-&gt;next = temp;
  cur-&gt;prev = temp;
  cout&lt;&lt;"Added node"&lt;&lt;endl;
  }
  
  void DList::addMiddleAfter(const int&amp;e, const int&amp; pos){
  DNode* temp = new DNode(e);
  DNode* cur = head;
  
  while((cur-&gt;elem) != pos){
      cur = cur -&gt; next;
  }
  
  temp -&gt;next = cur-&gt;next;
  temp-&gt;prev = cur;
  cur-&gt;next-&gt;prev = temp;
  cur-&gt;next = temp;
  cout&lt;&lt;"Added node"&lt;&lt;endl;
  
  }
  
  void DList::removeFront(){
  DNode* temp = head;
  temp-&gt;next-&gt;prev = head;
  head = head -&gt; next;
  delete temp;
  cout&lt;&lt;"Deleted Front"&lt;&lt;endl;
  }
  
  
  void DList::removeRear(){
  DNode* temp = tail;
  temp-&gt;prev-&gt;next = tail;
  tail = tail -&gt; prev;
  delete temp;
  cout&lt;&lt;"Deleted Rear"&lt;&lt;endl;
  }
  
  void DList::removeNode(const int &amp; e){
  DNode* cur = head;
  while((cur-&gt;elem) != e){
      cur = cur -&gt; next;
  }
  cur-&gt;prev-&gt;next = cur-&gt;next;
  cur-&gt;next-&gt;prev = cur-&gt;prev;
  delete cur;
  cout&lt;&lt;"Deleted node"&lt;&lt;endl;
  }
  
  bool DList::isIn(const int &amp;e){
  DNode* cur = head;
  while((cur-&gt;next) != tail){
      if (cur-&gt;elem == e){
          cout&lt;&lt;"Found"&lt;&lt;endl;
          return true;
      }
  cur = cur-&gt;next;
  }
  cout&lt;&lt;"Not found"&lt;&lt;endl;
  return false;
  }
  
  DList::~DList(){
  while((!isEmpty())) removeFront();
  }
  </code></pre>
  
  <p>DNode.cpp</p>
  
  <pre><code>#include "DNode.h"
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include "DList.h"
  #include "DNode.h"
  #include &lt;iostream&gt;
  
  using namespace std;
  
  DList newList;
  int main()
  {
      newList.addFront(50);
      newList.addRear(4);
      newList.display();
      return 0;
  }
  </code></pre>