title: How to make a linked list in using structs?
body: <p>I've seen a few topics about linked lists, and I've read enough to glean how to do it generally, but I want to make sure I'm not wrongly interpreting the information I've gathered.</p>
  
  <p>Let's say I have:</p>
  
  <pre><code>struct element 
  {
      int       val;
      element   *next;
  };
  </code></pre>
  
  <p>The element *next is a pointer to an element, which will be used to connect the elements together in order to form the linked list.</p>
  
  <p>I've also gathered that you need to have some kind of "tie off" so you don't lose your list. My professor describes it as a trail of balloons, and if you dont have a "tie off" your list can get lost.</p>
  
  <p>So I start off with creating the "tie off" pointer:</p>
  
  <pre><code>element first;
  first -&gt; *next = 0; // or null
  </code></pre>
  
  <p>This is where I get lost... How do I add to the head of a linked list? Ordering it isn't important at this point, I just need to start with an unordered list, I'll get more  complicated later.</p>
  
  <p>Something like this?</p>
  
  <pre><code>element addMe;
  addMe -&gt; val = 100;
  
  first -&gt; next = *addMe;
  </code></pre>
  
  <p>Is that right?</p>
  
  <p>What would I do to add something to a non-empty list? </p>
  
  <p>Thanks for the time!</p>
  
  <p>Edit: This is not homework. We have gone over linked lists, and have done an assignment with them. I did not get a very good grade on the assignment, so I am trying to strengthen my understanding before the next assignment. We <em>will</em> use linked lists again.</p>
  
  <p>Edit2: Thanks!</p>
  
  <p>I do not know if this would be considered "homework" or not. I personally do not think it is, considering I will not be using the code I posted here.</p>