title: Deleting a Node in a Linked List in C++
body: <p>I am trying to delete a node in a singly linked list at the nth position of the list, but I keep receiving a segmentation fault:11 when running the project. Below is my function <code>remove</code> where I believe the problem is, but I can not seem to figure why its not working because the logic makes sense. Also  where <code>headM</code> points as in the first item in the list is the 0th position. 
  Before I make the call to remove my list is the order <code>770 440 330 220 110</code>
  I make two calls to remove </p>
  
  <pre><code>remove(0)
  remove(2)
  </code></pre>
  
  <p>the list after should be <code>440 330 110</code>, but right now I am getting <code>770 330 110</code>....</p>
  
  <pre><code>void SimpleList::remove(int n)
  {
  if( n &lt; 0 || n &gt; sizeM ) { 
      return;
  }
  Node* p = headM;
  for( int c = 0; c &lt; n - 1; c++ )
  {
      p = p-&gt;next;
      //assert( p != nullptr );
  }
  Node* const p_doomed = p-&gt;next;
  //assert( p_doomed != nullptr );
  p-&gt;next = p_doomed-&gt;next;
  delete p_doomed;
  --sizeM;
  }
  </code></pre>
  
  <p>And below is the structure of the node. This part is correct because my <code>push_front</code> and <code>push_back</code> work.</p>
  
  <pre><code>class Node {
  public:
      ListItem item;
      Node *next;
  };
  
  Node *headM;
  int sizeM;
  
  void destroy();
  // Deallocate all nodes, and sets headM to zero.
  
  void copy(const SimpleList&amp; source);
  // List becomes copy of source.
  </code></pre>