title: Queue implementation using Likedlist and structures in C
body: <p>I don't understand what the problem is with this code. During compilation there are no errors, but while executing the given option of Enqueu it stops abruptly. The problem is occurring near Queue->rear->next=NULL which is correct in my view. I don't know where I'm going wrong.</p>
  
  <pre><code>struct ListNode
  {
         int data;
         struct ListNode *next;
  };
  
  struct Queue
  {
        struct ListNode *front;
        struct ListNode *rear;
  };
  
  struct Queue *createQueue()
  {
        struct Queue *Q;
        Q=malloc(sizeof(struct Queue));
        if(!Q)
             return NULL;
        Q-&gt;front=Q-&gt;rear=NULL;
        return Q;
  }
  
  int IsEmptyQueue(struct Queue *Q)
  {
        return (Q-&gt;front==NULL);
  }
  
  int EnQueue(struct Queue *Q,int data)
  {
      struct ListNode *newNode;
      newNode=malloc(sizeof(struct ListNode));
      if(!newNode)
                 return NULL;
      newNode-&gt;data=data;
      newNode-&gt;next=NULL;
      Q-&gt;rear-&gt;next=newNode;
      Q-&gt;rear=newNode;
      if(Q-&gt;front==NULL)
                  Q-&gt;front=newNode;
  }
  
  int main()
  {
      int choice=0,size,n;
      struct Queue *q;
      while(1)
      {
           printf("\nEnter the following");
           printf("\n1. Create a queue "); 
           printf("\n2.Enqueue");
           printf("\n7.Exit ");
           scanf("%d",&amp;choice);
  
           switch(choice)
           {
                      case 1:printf("\nCreate Queue");
                             q=createQueue();
                             break;
                      case 2:printf("\nInsert");
                             printf("\nEnter element to be inserted");
                             scanf("%d",&amp;n);
                             EnQueue(q,n);
                             break;
  
                      case 7:exit(0);
                      break;
  
        }
     }
  }
  </code></pre>