title: sorting linked list but getting segmentation fault
body: <p>Everytime i try to run this program i keep getting segmentation fault when i try to sort all the numbers in the linked list from smallest to greatest i found that it is somewhere in the while loop</p>
  
  <pre><code>while(marker_ptr-&gt;link()-&gt;link()!= NULL)
  {
    minum = prev-&gt;link();
    temp=minum-&gt;link();
    prev-&gt;set_link(temp);
    minum-&gt;set_link(head_ptr);
    head_ptr=minum;
    marker_ptr=minum-&gt;link();
  previouse_minimum(head_ptr);
      }
  </code></pre>
  
  <p>i have no idea what is wrong with it</p>
  
  <p>this is most of the code so you can get some context where i am using it</p>
  
  <pre><code>node(
      const value_type&amp; init_data = value_type( ),
      node* init_link = NULL
  )
  { data_field = init_data; link_field = init_link; }
  
  // Member functions to set the data and link fields:
      void set_data(const value_type&amp; new_data) { data_field = new_data; }
      void set_link(node* new_link)             { link_field = new_link; }
  
  // Constant member function to retrieve the data:
  value_type data( ) const { return data_field; }
  
  // Constant member functions to retreive the link:
      node* link( ) const          { return link_field; }
  
  private:
  value_type data_field;
  node* link_field;
  };
  
  node* previouse_minimum(node*&amp; head_ptr){
      node* cursor;
      node* minimum;
      node* prev;
      minimum=head_ptr;
  
      for(cursor=head_ptr; cursor != NULL; cursor=cursor-&gt;link())
        if(cursor-&gt;data() &lt; minimum-&gt;data())
           minimum=cursor;
  
      cursor = head_ptr;
      prev = cursor;
     while(cursor-&gt;link() != minimum)
      {
        cursor = cursor-&gt;link();
        prev = cursor;
  
      }
      cout &lt;&lt; prev-&gt;link()-&gt;data() &lt;&lt; endl;
      return prev;
  
  }
  
  void sort(node*&amp; head_ptr, node*&amp; marker_ptr)
  {
     node* print_ptr;
     node* prev = previouse_minimum(head_ptr);
     node* temp=NULL;
     node* minum;
     marker_ptr = head_ptr;
  
     while(marker_ptr-&gt;link()-&gt;link()!= NULL)
      {
        minum = prev-&gt;link();
        temp=minum-&gt;link();
        prev-&gt;set_link(temp);
        minum-&gt;set_link(head_ptr);
        head_ptr=minum;
        marker_ptr=minum-&gt;link();
        previouse_minimum(head_ptr);
      }
     for(print_ptr = head_ptr; print_ptr !=NULL; print_ptr = print_ptr-&gt;link())
     cout &lt;&lt;  print_ptr-&gt;data() &lt;&lt; " ";
  
     cout &lt;&lt; endl;
  
     }
  </code></pre>