title: Using linked list to create Queue data structure
body: <p>Iam trying to build a queue data structure that contains Nodes each node have integer value and a pointer to the next node there is something wrong with he deQueue(Queue q); function , it is returning elements like a stack (LIFO) here is my code and the output</p>
  <p>deQueue();</p>
  <pre><code>int deQueue(Queue* q){
       if(q-&gt;head)
      {
          int result;
          Node*temp=q-&gt;head;
          result=temp-&gt;value;
          q-&gt;head=temp-&gt;next;
          free(temp);
          if(q-&gt;head==NULL)
              q-&gt;tail=NULL;
          return result;
      }
  }
  </code></pre>
  <p>enQueue():</p>
  <pre><code>void enQueue(Queue* q ,Node* node){
  
      if(isEmpty(q)){
  
  
          q-&gt;head = q-&gt;tail = node;
          q-&gt;head-&gt;next = q-&gt;tail-&gt;next = NULL;
          q-&gt;size++;
      }
      else{
  
          q-&gt;tail-&gt;next = node;
          q-&gt;tail = node;
          q-&gt;tail-&gt;next = NULL;
          q-&gt;size++;
      }
  }
  </code></pre>
  <p>main():</p>
  <pre><code>int main()
  {
      Queue* q = initializerQueue();
      Node* n1 = newNode(10);
      Node* n2 = newNode(20);
      Node* n3 = newNode(30);
      Node* n4 = newNode(40);
  
      enQueue(q , n1);
      enQueue(q , n2);
      enQueue(q , n3);
      enQueue(q , n4);
  
      printQueue(q);
      printf(&quot;\n%d - %d - %d - %d &quot; , deQueue(q) , deQueue(q) , deQueue(q) , deQueue(q));
      return 0;
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/butmB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/butmB.png" alt="Output:" /></a></p>