title: Queue resets after every operation
body: <p>I am working on a queue implementation and something weird is happening. The Enqueue seems to work but the changes are not being registered (the size stays the same at 0). From what I can tell, the code will enqueue an element but immediately forget about it. The output is: <br>
  Data passed: a34<br>
  Back befor:(null)<br>
  Back a:a34<br>
  Data passed: bg<br>
  Back befor:(null)<br>
  Back a:bg<br>
  Print (null)<br>
  Print 0<br>
  Based on this I'm guessing it's something to do with memory and scope, but I'm not sure how to resolve it.Below is the code.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include "queue.h"
  
  typedef struct node_s{
      void* data;
      struct node_s* next;
  } node;
  
  // queue structure
  typedef struct queue_s{
      node* back;
      node* front;
      int size;
  } queue_t;
  
  //helpers
  node *newNode(void *data)
  {
          //create a new node* with data-&gt;data. @return: a node*
          node *temp = (node *)malloc(sizeof(node));
          temp-&gt;data = data;
          temp-&gt;next = NULL;
          return temp;
  }
  
  //deep copy a n2 
  node* copy(node* n2){
          node *temp = (node *)malloc(sizeof(node));
          temp-&gt;data=n2-&gt;data;
          temp-&gt;next=n2-&gt;next;
          return temp;
  }
  queue_t que_create(void)
  {
          queue_t new;
          new.size = 0;
          node *front = (node *)malloc(sizeof(node));
          node *back = (node *)malloc(sizeof(node));
          new.front=front;
          new.back=back;
          return new;
  }
  
  void que_destroy(queue_t queue)
  {
          while (queue.size &gt; 0)
          {
                  que_dequeue(queue);
          }
  }
  
  void que_clear(queue_t queue)
  {
          while (que_size(queue) != 0)
          {
                  que_dequeue(queue);
          }
  }
  
  void que_enqueue(queue_t queue, void *data)
  {
          // Create a new LL node
          printf("Data passed: %s\n",data);
          node *temp = newNode(data);
          // If queue is empty, then new node is front and back 
          if (queue.size == 0){
                  printf("Back befor:%s\n",queue.back-&gt;data);
                  queue.front = copy(temp);
                  queue.back = copy(temp);
                  queue.size=queue.size+1;
                  free(temp);
                  printf("Back a:%s\n",queue.back-&gt;data);
                  return;
          }
          // Add the new node at the end of queue
          queue.back-&gt;next = copy(temp);
          queue.back = temp;
          printf("Back2:%s\n",queue.back-&gt;data);
  
           if (data != NULL){
                  queue.size=queue.size+1;
          }
          //free(temp);
  }
  
  void que_dequeue(queue_t queue)
  {
          if (queue.size == 0)
          {
                  printf("Deq on an empty q");
                  return; //break here
          }
          else if (queue.size == 1)
          {
                  //only 1 element
                  queue.front = NULL;
                  queue.back = NULL;
          }
          else
          {
                  node* temp = newNode(NULL);
                  temp=queue.front-&gt;next;
                  queue.front = copy(temp);
                  free(temp);
          }
          queue.size=queue.size-1;
  }
  
  const void *que_front(const queue_t queue)
  {
          //return queue.front-&gt;data;
          return queue.front;
  }
  
  size_t que_size(queue_t queue)
  {
          return (size_t)queue.size;
  }
  
  int main(void){
          queue_t q=que_create();
          que_enqueue(q,"a34");
          que_enqueue(q,"bg");
          node* f=(node *)que_front(q);
          printf("Print %s\n",f-&gt;data);
          printf("Print %d\n",q.size);
          return 0;
  }
  </code></pre>