title: Deque implementation based on doubly linked list not working
body: <p>here is my code for deque implementation using doubly linked list. It is not working..can u get me some pointers on where i am going wrong. The pointers are not initialised and the code is getting stuck in the addqatend function.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;conio.h&gt;
  #include &lt;iostream&gt;
  #include &lt;string.h&gt;
  #include&lt;time.h&gt;
  #include&lt;math.h&gt;
  #include&lt;ctype.h&gt;
  #include &lt;malloc.h&gt;
  #include &lt;Windows.h&gt;
  
  struct node
  {
  struct node *prev;
  int data;
  struct node *next;
  };
  
  struct queue
  {
  struct node *front;
  struct node *rear;
  };
  
  
  void initqueue(struct queue *);
  void addqatbeg(struct queue *,int);
  void addqatend(struct queue *, int);
  int delqatbeg(struct queue *);
  int delqatend(struct queue *);
  void delqueue(struct queue *);
  
  int main()
  {
  struct queue a;
  int i;
  
  system("cls");
  initqueue(&amp;a);
  
  addqatbeg(&amp;a,11);
  addqatbeg(&amp;a,23);
  addqatbeg(&amp;a,-5);
  addqatbeg(&amp;a,45);
  
  addqatend(&amp;a,34);
  addqatend(&amp;a,78);
  
  i = delqatbeg(&amp;a);
  if(i!=NULL)
      printf("item deleted from front:%d",i);
  i = delqatbeg(&amp;a);
  if(i!=NULL)
      printf("item deleted from front:%d",i);
  i = delqatend(&amp;a);
  if(i!=NULL)
      printf("item deleted from end:%d",i);
  i = delqatend(&amp;a);
  if(i!=NULL)
      printf("item deleted from end:%d",i);
  
  delqueue(&amp;a);
  
  system("pause");
  return 0;
  }
  
  //initialise the queue
  void initqueue(struct queue *q)
  {
  q-&gt;front = q-&gt;rear = NULL;
  }
  
  //add at the beginning of the queue
  void addqatbeg(struct queue *q,int item)
  {
  struct node *temp;
  temp = (struct node *)malloc(sizeof(struct node));
  if(temp == NULL)
      printf("queue is full\n");
  //temp-&gt;data = item;
  //temp-&gt;link = NULL;
  if(q-&gt;front == NULL)
  {
      q-&gt;rear = q-&gt;front = temp;
      q-&gt;front-&gt;prev = NULL;
      q-&gt;front-&gt;next = NULL;
      q-&gt;rear-&gt;next = NULL;
      q-&gt;rear-&gt;prev = NULL;
      return;
  }
  
  
  q-&gt;front-&gt;data = item;
  q-&gt;front-&gt;next = temp;
  q-&gt;front = temp;
  q-&gt;front-&gt;prev = q-&gt;front;
  //q-&gt;rear-&gt;next = q-&gt;front-&gt;next;
  //q-&gt;front-&gt;prev = q-&gt;rear;
  }
  
  //add at the end of the queue
  void addqatend(struct queue *q, int item)
  {
  struct node *temp;
  temp = (struct node*)malloc(sizeof(struct node));
  if(temp == NULL)
      printf("queue is full\n");
  if(q-&gt;front == NULL)
  {
      q-&gt;rear = q-&gt;front = temp;
      q-&gt;front-&gt;prev = NULL;
      q-&gt;front-&gt;next = NULL;
      return;
  }
  while(q-&gt;front-&gt;next!=NULL)
      q-&gt;rear = q-&gt;front-&gt;next;
  q-&gt;rear-&gt;data = item;
  q-&gt;rear-&gt;next =temp;
  q-&gt;rear = q-&gt;rear-&gt;next;
  q-&gt;rear-&gt;prev = q-&gt;rear;
   }
  
  //delete at the beginning of the queue
  int delqatbeg(struct queue *q)
  {
  struct node *temp;
  int item;
  if(q-&gt;front ==NULL)
  {
      printf("queue is empty:\n");
      return NULL;
  }
  item = q-&gt;front-&gt;data;
  temp = q-&gt;front;
  q-&gt;front = q-&gt;front-&gt;next;
  free(temp);
  return item;
   }
  
  //delete at the end of the queue
   int delqatend(struct queue *q)
  {
  struct node *temp;
  int item;
  if(q-&gt;rear == NULL)
  {
      printf("queue is empty\n");
      return NULL;
  }
  item = q-&gt;rear-&gt;data;
  temp = q-&gt;rear;
  q-&gt;rear = q-&gt;rear-&gt;prev;
  free(temp);
  return item;
  }
  
  //free the nodes
   void delqueue(struct queue *q)
  {
  struct node *temp;
  
  if(q-&gt;front == NULL)
      return;
  while(q-&gt;front!=NULL)
  {
      temp = q-&gt;front;
      q-&gt;front = q-&gt;front-&gt;next;
      free(temp);
  }
  }
  </code></pre>