title: dequeueing function working with 2 queues encounters segfault?
body: <p>The function below is supposed to dequeue a structure that is made of 2 queues. Each time we dequeue the first queue, its rear needs to become the front of the second queue. Essentially moving the first element in the second queue to the first queue to be its rear. I came up with the algorithm below:</p>
  <pre><code>int dequeue(queue* Q1,queue* Q2){
  
      node* temp;
  
      if(Q1-&gt;rear=NULL){
          return 0;
      }
  
      if(count&lt;3){
          temp=Q1-&gt;front;
          Q1-&gt;front=Q1-&gt;front-&gt;next;
          free(temp);
          count--;
          return 1;
      }
  
      if(count&gt;=3){
  
          temp=Q1-&gt;front;
          Q1-&gt;front=Q1-&gt;front-&gt;next;
          free(temp);
  
          Q1-&gt;rear-&gt;next=Q2-&gt;front;
          Q1-&gt;rear=Q1-&gt;rear-&gt;next;
          Q2-&gt;front=Q2-&gt;front-&gt;next;
          Q1-&gt;rear-&gt;next=NULL;
  
          if(Q2-&gt;front=NULL){
              Q2-&gt;rear=NULL;
          }
  
          count--;
          return 1;
  
      }
  }
  </code></pre>
  <p>It gives a segfault at <code>Q1-&gt;rear-&gt;next=Q2-&gt;front;</code></p>
  <p>is there an alternative way to achieve this?</p>