title: C: Enqueue() - Inserting at the end of a linked list, returning head of list
body: <p>I'm very new to programming. Trying to write a function that receives the head of a list + the data to be inserted -- and passes back the new head of the list. I've done this a lot with adding an element to the head of a list, but for some reason I can't wrap my head around this slight difference.</p>
  
  <pre><code>#include &lt;assert.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  typedef struct node_{
      int data;
      struct node_ *next;
  } Queue;
  
  int main(void){
  
     Queue* queue = NULL;
  
     queue = enqueue(queue, 1);
  
     assert(queue-&gt;next == NULL);
     assert(queue-&gt;data == 1);
  
     queue = enqueue(queue, 2);
  
     assert(queue-&gt;data == 1);
     assert(queue-&gt;next != NULL);
     assert(queue-&gt;next-&gt;data == 2);
  
     free(queue-&gt;next);
     free(queue);
  
     return 0;
  
  }
  
  Queue *enqueue(Queue *queue, int data){
  
      Queue *new_node, *p;
  
      new_node = malloc(sizeof(Queue));
  
      new_node-&gt;data = data;
      new_node-&gt;next = NULL;
  
      p = queue;
  
      while(p-&gt;next != NULL){
          p = p-&gt;next;
      }
  
      p-&gt;next = new_node;
  
      return ??????
  
  }
  </code></pre>
  
  <p>I know that to insert to the head, you can:</p>
  
  <pre><code>new_node-&gt;data = data; 
  new_node-&gt;next = queue;
  return new_node;
  </code></pre>
  
  <p>Apologies if what I've written above doesn't make much sense. I'm pretty tired and I've gone through quite a few iterations. Probably missing something obvious. </p>