title: Queue performance wise which is better implementation - Array or Linked list
body: <p>Which way gives the faster enqueueing and dequeuing when I have to insert very few elements, Is array better than a linked list?</p>
  
  <p>I need to insert few element and I have to remove and read that removed element from queue.
  If it is array I may have to modify the indexes every time I remove an element. Inserting and deleting may happen simultaneously also. </p>
  
  <p>Which one is better from below case?</p>
  
  <pre><code>typedef struct{
      mylist list;
      struct mylistQ *next;
  }mylistQ;
  </code></pre>
  
  <p><strong>Array Code</strong>  </p>
  
  <pre><code> static mylist myListQ[QUEUESIZE+1];
  int qLast = 0;
  
  void enqueue_element(mylist qItem)
  {
          myListQ[qLast] = qItem;
      qLast++;
  }
  
  mylist dequeue_element()
  {
   retryq:
     if(qLast &gt;0) {
      mylist qReturn = myListQ[0];  
      int i;
      for (i = 0; i &lt; qLast - 1; i++){
          myListQ[i] = myListQ[i + 1];
      }
      qLast--; 
      return qReturn;
       }
     else {
      goto retryq;
      }
  }
  </code></pre>
  
  <p><strong>Linked List</strong>    </p>
  
  <pre><code> int qLast = 0;
  
  mylistQ *headElement = NULL;   
  mylistQ *tailElement = NULL;     
  
  void enqueue_element(mylist *List)
  {
      mylistQ *newnode;      
      newnode=(mylistQ*)av_malloc(sizeof(mylistQ));
      newnode-&gt;next=NULL;
      newnode-&gt;list=*List;
      qLast++;
      if(headElement==NULL &amp;&amp; tailElement==NULL)
      {
          headElement=newnode;
          tailElement=newnode;
      }
      else
      {
          tailElement-&gt;next=newnode;
          tailElement=newnode;
      }
   }
  
  mylist dequeue_element()
  {
      mylistQ *delnode;      /* Node to be deleted */
      mylist Dellist;
      if(headElement==NULL &amp;&amp; tailElement==NULL){
          LOg( "Queue is empty to delete any element");
          }
      else
      {
         Log("In dequeue_picture queue is not empty");
          delnode=headElement;
          headElement=headElement-&gt;next;
      if (!headElement){
          tailElement=NULL;
      }
          Dellist = delnode-&gt;list;
          av_free(delnode);
      qLast--;
      }
          return Dellist;
  }
  </code></pre>