Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you insert into a sorted linked list?
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/1315263/linkedlist-node-jump">LinkedList “node jump”</a> </p> </blockquote> <p>I just need to have a linked list in order by name. I can only get it as far as 1st, 3rd, 5th, .. nodes. I just can't think this far. I want to be a C++ programmer but if I can't understand this is their any hope? STL containers <code>std::lists</code> are not an option for me at this point as a student. What you see in the list function is what I am TRYING to understanding.</p> <pre><code>list::node::node(const winery &amp;winery) : item( winery.getName(), winery.getLocation(), winery.getAcres(), winery.getRating() ), nextByName( NULL ), nextByRating( NULL ) { } void list::insert(const winery&amp; winery) { node *current_node = new node( winery ); // but came here and did this so it has new info! node *next_node = NULL; node *tail_node = current_node; if ( headByName == NULL ) // then we are here for the first item { headByName = current_node; // the list ptrs will have the first node's address. headByRating = current_node; } while ( headByName-&gt;nextByName != NULL ) { headByName-&gt;nextByName = tail_node; tail_node = next_node; //next_node = current_node; } tail_node = new node( winery ); headByName-&gt;nextByName = tail_node; } </code></pre> <p>And the pointers that are available to me:</p> <pre><code>struct node { winery item; node * nextByName; node * nextByRating; }; class list { ... private: node * headByName; node * headByRating; }; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload